title: Corrupted file from aws s3
body: <p>The file I get from the backend says it's corrupted (pdf) or shows nothing (image/png).</p>
  <p>This is how I upload to AWS:</p>
  <pre><code>const s3 = new AWS.S3();
  
  try {
    await s3.upload({
      Bucket: bucket,
      Key: filename,
      Body: file,
      ContentType: mimetype,
      ContentDisposition: contentDisposition,
    }).promise();
  
      return { success: true, data: null };
    } catch(e) {
      return { success: false, data: null, message: e.code };
  }
  </code></pre>
  <p>This is how I get the object from AWS</p>
  <pre><code>try {
    const data = await s3.getObject({Bucket: bucket, Key: idAWSFile}).promise()
  
    return { success: true, data }
  } catch(e) {
    return { success: false, data: null, message: e.code };
  }
  </code></pre>
  <p>This is the object I get in the client side.</p>
  <pre><code>{
    AcceptRanges: &quot;bytes&quot;,
    Body: &lt;Buffer&gt;,
    ContentDisposition: &quot;attachment; filename = &quot;blablabla&quot;&quot;,
    ContentLength: 23361,
    ContentType: &quot;application/pdf&quot;,
    ETag: &lt;randomnumbers&gt;,
    LastModified: &lt;DATE&gt;,
    Metadata: {},
  }
  </code></pre>
  <p>This is how I'm trying to download it in the client side:</p>
  <pre><code>const blob = new Blob([data.Body], { type: data.ContentType });
  const url = URL.createObjectURL(blob)
  window.open(url)
  </code></pre>
  <p>What have I tried doing:</p>
  <ol>
  <li>I tried with <code>file-saver</code> and same result -&gt; corrupted file</li>
  <li>I tried using <code>toString(utf-8)</code> on the Body in the <code>s3.getObject</code> function as I saw in other SO answers. But when I do this I get gibberish in the Body on the client side and don't know and haven't found what to do with it.</li>
  </ol>