diff --git a/index.js b/index.js index aa5c684..264a7e6 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,7 @@ function getBoundary(event) { module.exports.parse = (event, spotText) => { const boundary = getBoundary(event); const result = {}; + const contentTypeRegex = /Content-Type:\s.+/gi; event.body .split(boundary) .forEach(item => { @@ -19,9 +20,9 @@ module.exports.parse = (event, spotText) => { result[item.match(/name=".+";/g)[0].slice(6, -2)] = { type: 'file', filename: item.match(/filename=".+"/g)[0].slice(10, -1), - contentType: item.match(/Content-Type:\s.+/g)[0].slice(14), - content: spotText? Buffer.from(item.slice(item.search(/Content-Type:\s.+/g) + item.match(/Content-Type:\s.+/g)[0].length + 4, -4), 'binary'): - item.slice(item.search(/Content-Type:\s.+/g) + item.match(/Content-Type:\s.+/g)[0].length + 4, -4), + contentType: item.match()[0].slice(14), + content: spotText? Buffer.from(item.slice(item.search(contentTypeRegex) + item.match(contentTypeRegex)[0].length + 4, -4), 'binary'): + item.slice(item.search(contentTypeRegex) + item.match(contentTypeRegex)[0].length + 4, -4), }; } else if (/name=".+"/g.test(item)){ result[item.match(/name=".+"/g)[0].slice(6, -1)] = item.slice(item.search(/name=".+"/g) + item.match(/name=".+"/g)[0].length + 4, -4);