I'm not asking about uploading a file from a browser to a nodejs script.
But I am looking for the option to upload the file to another server, example I will have a nodejs in server called A,
I want to upload the file(/file_path/filename.realm) to Server called B(AWS S3).
You have to use aws-sdk for this purpose and you follow:
(Note: Considering that you have access to AWS S3 and already created it)
sample code:
const fs = require('fs');
const AWS = require('aws-sdk');
const s3 = new AWS.S3({
accessKeyId: <awsS3AccessId>, // access Id of your bucket
secretAccessKey:<awsS3SecretKey>, // secret key of your bucket
});
const uploadFile = (fileName) => {
// Read content from the file
const fileContent = fs.readFileSync(fileName);
// Setting up S3 upload parameters
const params = {
Bucket: BUCKET_NAME,
Key: fileName, // File name you want to save as in S3
Body: fileContent
};
// Uploading files to the bucket
s3.upload(params, function(err, data) {
if (err) {
throw err;
}
console.log(`File uploaded successfully. ${data.Location}`);
});
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.