I am getting some meta-information / junk in CSV in lambda function. I need to remove that junk. If I directly save the file to s3 the junk is included. Could anyone guide me on how to remove this?
----------------------------362648820336892682391117 ***// remove this***
Content-Disposition: form-data; name="file"; filename="Book1.csv" ***// remove this***
Content-Type: text/csv ***// remove this***
o;?name,age // remove this o;?
andy,33
hello,34
----------------------------362648820336892682391117-- ***// remove this***
I can also upload directly to s3 using pre-signed URL however, that is not what I am looking for.
const AWS = require('aws-sdk');
exports.handler = async (event) => {
try {
console.log(JSON.stringify(event, 2, null));
const data = new Buffer(event.body, 'base64');
const text = data.toString('ascii');
const s3 = new AWS.S3();
const params = {Bucket: 'bucket', Key: 'key', Body: text};
const d = await s3.upload(params).promise();
return {
statusCode: 200,
body: JSON.stringify('uploaded successfully'),
};
} catch (e) {
return {
statusCode: 200,
body: JSON.stringify('uploaded successfully'),
};
}
};
Thanks