node.jsamazon-web-servicesamazon-s3pre-signed-urlsigned-url

Upload file with AWS S3 signed url always setting content-type binary/octet-stream


I am facing a problem where the content-type always changes during the upload process. I am using lambda and nodejs to generate a URL. Here is my code. I would be grateful for any help! enter image description here

enter image description here

enter image description here

enter image description here


Solution

  • Your code for generating the Signed URL works ok. The problem seems to be with the actual uploading of the file. Try these options and let's see if you get a better result:

    1. In postman use the binary option and not the form-data

      form-data adds a lot of additional values

    2. Create a nodejs file and test with this code

      const axios = require('axios');
      const fs = require('fs');
      
      (async () => {
          const file = fs.readFileSync('./download.mp4');
      
          await axios.put(signedUrl, {
              data: file,
          }, {
              headers: {
                  'Content-Type': 'video/mp4'
              }
          });
      
      })();
      

      The result I get: enter image description here