S3 - Video, uploaded with getSignedUrl link, does not play and is downloaded in wrong format

Viewed 170

I am using AWS SDK in Server Side with Node.JS and having issue with uploading files as formData from client side.

On the server side I have simple route, which creates upload link, where video will be uploaded later directly from client side.

I am using S3 getSignedUrl method for generating that link with putObject, which creates PUT request for client, but causes very strange issue with formData.

Video uploaded as formData is not behaving correctly - instead of playing it S3 uploaded url downloads that video and it is also broken.

Here is simple how i configure that method on server side:

this.s3.getSignedUrl(
    'putObject',
    {
      Bucket: '<BUCKET_NAME>',
      ContentType: `${contentType}` -> video/mp4 as a rule,
      Key: key,
    },
    (err, url) => {
      if (err) {
        reject(err)
      } else {
        resolve(url)
      }
    },
  )

axios put request with blob is actually working, but not for formData.

axios.put(url, file, {
  headers: {
    'Content-Type': file.type,
  },
  onUploadProgress: ({ total, loaded }) => {
    setProgress((loaded / total) * 100)
  },
})

This is working version, but when I try to add file to formData, it is uploaded to S3, but video downloads instead of playing.

I do not have big experience in AWS, so if somebody knows how to handle that issue, I will be thankfull

0 Answers
Related