aws-s3 icon indicating copy to clipboard operation
aws-s3 copied to clipboard

ReferenceError: FormData is not defined

Open timgrubb opened this issue 7 years ago • 11 comments

I'm not sure why I get this when I do uploadFile

timgrubb avatar Sep 26 '18 07:09 timgrubb

Where are you uploading the file from ?

Fausto95 avatar Sep 28 '18 15:09 Fausto95

From the IOS simulator gallery.

Tim

Sent from my iPhone

On Sep 28, 2018, at 8:17 AM, Faustino Kialungila [email protected] wrote:

Where are you uploading the file from ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

timgrubb avatar Sep 28 '18 15:09 timgrubb

I am getting this error also. Uploading from my local

KefLesser avatar Oct 09 '18 20:10 KefLesser

I get the same error with NodeJS v10.13.0. It is because the NodeJS doesn't natively include the FormData class.

One should include this package: https://www.npmjs.com/package/form-data And replace: var r=new FormData with: var r=new require('form-data')

Or something similar...

AdrienCourtois avatar Mar 04 '19 22:03 AdrienCourtois

getting the same error

helxsz avatar Mar 24 '19 12:03 helxsz

This is a client-side library, it only works on the browser for the moment! But you can send a PR to support server-side uploading!

Fausto95 avatar Mar 24 '19 18:03 Fausto95

Getting the same error here

ishanbhutagate6 avatar Mar 25 '19 04:03 ishanbhutagate6

i getting same error and i am using graphql apollo server and client for the same kindly let me know solution for the same

logindharam avatar Apr 05 '19 09:04 logindharam

This is a client-side library, it only works on the browser for the moment! But you can send a PR to support server-side uploading!

The README should say that. I lost an hour on this.

jpidelatorre avatar May 31 '19 21:05 jpidelatorre

Why would you want to use a client side library for node when there an official sdk for node. Here is sample code you can use to upload files to AWS S3 using aws-sdk package:

const fs = require('fs')
const path = require('path')
const S3 = require('aws-sdk/clients/s3')

let file = '/path/to/your/file'

let s3 = new S3({
  accessKeyId: 'your-access-key-id',
  secretAccessKey: 'your-secret-key',
})

const config = {
  Key: path.basename(file),
  Bucket: 'your-bucket-name',
  Body: fs.createReadStream(file),
}

s3.upload(config, function (err, data) {
  console.log(err, data)
})

arashmilani avatar Apr 18 '20 11:04 arashmilani

I am getting the same error, using material-ui-dropzone to fetch pdf files from reactjs, passing it to nodejs server and using aws-s3 to insert it into AWS S3.

I tried what @arashmilani recommended but it didn't work, can anyone help me? It will be a great help.

Thanks.

Ved111 avatar Mar 05 '21 17:03 Ved111