Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
Upload a file buffer using request promise to Amazon S3

I'm using the request-promise library. I'm trying to upload a file to a signed Amazon S3 URL:

var fs = require('fs')
var request = require('request-promise-native')
request({
  method: 'PUT',
  uri: 'https://MYBUCKET.amazonaws.com/myfile.pdf?AWSAccessKeyId=KEY&Expires=1489006131&Signature=SIGNATURE',
  headers: {
    'x-amz-server-side-encryption': 'AES256',
    'Content-Type': 'application/pdf'
  },
  file: fs.readFileSync('myfile.pdf')
}).then((r) => console.log('response', r)).catch((err) => console.log('err', err))

The request succeeds, but Amazon reports the file as 0 bytes in length.

Is the file parameter the correct argument?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I believe you want

body: fs.readFileSync('myfile.pdf')

instead of

file: fs.readFileSync('myfile.pdf')

Additionally, you can stream the file instead of buffering the entire file in memory first:

body: fs.createReadStream('myfile.pdf')

See the request documentation for more information.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!