title: Uploading Image to S3 bucket stores it as application/octet-stream, but I want to store it as an image to use it (JavaScript / Node)
body: <p>I want my users to upload profile pictures. Right now I can choose a file and pass it into a POST request body. I'm working in Node.js + JavaScript.</p>
  <p>I am using DigitalOcean's Spaces object storage service to store my images, which is S3-compatible.</p>
  <p>Ideally, my storage stores the file as an actual image. Instead, it is storing as a strange file with Content-Type application/octet-stream. I don't know how I'm supposed to work with this -- normally to display the image, I simply reference the URL that hosts the image, but in this case the URL is pointing to this strange file. It is named something like VMEDFS3Q65JV4B7YQKLS (no extension). The size of the file is 14kb which seems right and it appears to hold the file data. It looks like this:</p>
  <p><a href="https://i.stack.imgur.com/WV9aU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WV9aU.png" alt="enter image description here" /></a></p>
  <p>etc...</p>
  <p>I know I'm grabbing the right image and I know the database is hooked up properly as it's posting to the exact right place, I'm just unhappy with the file type.</p>
  <p>Request on front end:</p>
  <pre><code>fetch('/api/image/profileUpload', { 
        method: 'PUT',
        body: { file: event.target.files[0] },
        'Content-Type': 'image/jpg',
      })
  </code></pre>
  <p>Code in backend:</p>
  <pre><code>      const AWS = require('aws-sdk')
  
        let file = req.body;
        file = JSON.stringify(file);
          
        AWS.config.update({
          region: 'nyc3',
          accessKeyId: process.env.SPACES_KEY,
          secretAccessKey: process.env.SPACES_SECRET,
        });
        
        const s3 = new AWS.S3({
          endpoint: new AWS.Endpoint('nyc3.digitaloceanspaces.com')
        });
      
        const uploadParams = {
          Bucket: process.env.SPACES_BUCKET,
          Key: process.env.SPACES_KEY,
          Body: file,
          ACL: &quot;public-read&quot;,
          ResponseContentType: 'image/jpg'
        };
      
        s3.upload(uploadParams, function(err, data) {
          if (err) console.log(err, err.stack);
          else console.log(data);
        });
  </code></pre>
  <p>What I've tried:</p>
  <ul>
  <li>Adding content-type header in request and content-type parameters in back</li>
  <li>Other methods of fetching the data in the backend -- they all result in the same thing</li>
  <li>Not stringifying the file after grabbing it from the req.body</li>
  <li>Changing POST request to PUT request</li>
  </ul>
  <p>Would appreciate any insight into either a) converting this octet-stream file into an image or b) getting this image to upload as an image. Thank you</p>