Skip to content

How to upload the file using fs? #4430

Answered by RanVaknin
kotnibf asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @lonelytechpot ,

You can use it like this:

const AWS = require("aws-sdk");
const fs = require("fs");

const s3 = new AWS.S3();

const file = fs.readFileSync("/path/to/your/file/helloworld.txt");

const params = {
    Bucket: "my-bucket", 
    Key: "my-key", 
    Body: file
};

s3.upload(params, function(err, data) {
    if (err) {
        console.log("Error!", err);
    } 
    if (data) {
        console.log("Success!", data.Location);
    }
});

You need to supply a correct path to the file you want to read from disk with fs.

Let us know if you need anything else,
Ran~

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by RanVaknin
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
2 participants