Created
September 2, 2022 11:03
-
-
Save Shaxadhere/a325a81018b022182117a1206072befa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const s3 = new AWS.S3({ | |
accessKeyId: process.env.AWS_ACCESS_KEY, | |
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, | |
}); | |
const uploadFile = () => { | |
fs.readFile(file.filepath, (err, data) => { | |
if (err) { | |
res.status(400).send(ApiResponse({}, err.message, false)); | |
} | |
const params = { | |
Bucket: "bucket-name", // pass your bucket name | |
Key: fileName, // file will be saved as testBucket/contacts.csv | |
Body: JSON.stringify(data, null, 2), | |
}; | |
s3.upload(params, function(s3Err, data) { | |
if (s3Err) { | |
res.status(400).send(ApiResponse({}, s3Err, false)); | |
} | |
console.log(`File uploaded successfully at ${data.Location}`); | |
fields.document = data.Location; | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment