Upload a file to Amazon S3 with NodeJS

后端 未结 7 801

I ran into a problem while trying to upload a file to my S3 bucket. Everything works except that my file paramters do not seem appropriate. I am using Amazon S3 sdk to uploa

相关标签:
7条回答
  • Upload CSV/Excel

    const fs = require('fs');
    const AWS = require('aws-sdk');
    
    const s3 = new AWS.S3({
        accessKeyId: XXXXXXXXX,
        secretAccessKey: XXXXXXXXX
    });
    
    const absoluteFilePath = "C:\\Project\\test.xlsx";
    
    const uploadFile = () => {
      fs.readFile(absoluteFilePath, (err, data) => {
         if (err) throw err;
         const params = {
             Bucket: 'testBucket', // pass your bucket name
             Key: 'folderName/key.xlsx', // file will be saved in <folderName> folder
             Body: data
         };
          s3.upload(params, function (s3Err, data) {
                        if (s3Err) throw s3Err
                        console.log(`File uploaded successfully at ${data.Location}`);
                        debugger;
                    });
      });
    };
    
    uploadFile();
    
    0 讨论(0)
提交回复
热议问题