0

I am trying to upload videos from react native application to aws s3 bucket using nodejs backend server. My approach is,

  1. Convert video to base64 at react native application level
  2. Send POST request to backend server by attaching base64 data as formdata in request
  3. Upload into s3 bucket using multer at the backend server.

I am facing few problems with this approach

I can upload small size of videos (kb), When I'm trying to upload 4mb video It is working fine in my local machine, but in server (aws ec2 instance with 1Gb memory) this caused server to get stuck.

const params = {
      Bucket: S3_VIDEO_BUCKET_NAME,
      Key: `${name}`,
      Body: bufferContent,
      ContentEncoding: 'base64',
      ContentType: `${context}/${type}`,
}

s3.upload(params, function (err, data) {
        if (err) {
          console.log('Error', err)
          isError = true
        }
        if (data) {
          console.log('Upload Success', data.Location)
          console.log(`${S3_VIDEO_CLOUD_FRONT_DOMAIN}${data.Key}`)
          key = data.Key
        }
})
  1. Why remote server get stuck when I upload video which has size about (4mb) and local server does not have that issue ?

  2. Is converting to base 64 the best approach or Is there a way to upload videos to s3 bucket without converting video to base 64 ?

Edited => I am using multer and maximum fieldSize is 20mb.

var upload = multer({ limits: { fieldSize: 20 * 1024 * 1024 } }) 
John Stuart
  • 950
  • 5
  • 11
  • 28

1 Answers1

0

If Your server uses nginx, then you might want to check the client_max_body_size which is mostly default at 1mb Changing Nginx body size

cupid22
  • 161
  • 7
  • I am using multer, `var upload = multer({ limits: { fieldSize: 20 * 1024 * 1024 } })` , already set to 20mb. This is not an issue because in my local machine 4mb file upload is a success. – John Stuart Jul 05 '21 at 13:24
  • Your server maybe uses a proxy server and even proxy servers have limit to upload, you can check that – cupid22 Jul 06 '21 at 06:41