-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload.js
44 lines (37 loc) · 1.25 KB
/
upload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var AWS = require("aws-sdk");
var fs = require("fs");
var path = require("path");
function upload(fileName, files) {
// let uploadButton = document.getElementById("upload-button");
// let chosenImage = document.getElementById("chosen-image");
// let fileName = document.getElementById("file-name");
console.log("fileName Upload func", fileName);
console.log("fileName Uplaod func", files);
// Set the region
AWS.config.update({ region: "ap-south-1" });
// Create S3 service object
var s3 = new AWS.S3({ apiVersion: "2006-03-01" });
// Configure the file stream and obtain the upload parameters
var fileStream = fs.createReadStream(fileName);
fileStream.on("error", function (err) {
console.log("File Error", err);
});
// call S3 to retrieve upload file to specified bucket
var uploadParams = {
Bucket: "sih-project-vss",
Key: path.basename(fileName),
Body: fileStream,
};
// uploadParams.Body = fileStream;
// uploadParams.Key = path.basename(file);
// call S3 to retrieve upload file to specified bucket
s3.upload(uploadParams, function (err, data) {
if (err) {
console.log("Error", err);
}
if (data) {
console.log("Upload Success", data.Location);
}
});
}
module.exports = upload;