1

I'm trying to download a file uploaded on S3. The file is well saved but impossible to download it. My result is a blank new tab. Any idea where the issue come ? Here is the back end code :

try:
    response = s3.get_object(
        Bucket=os.environ["BUCKET"],
        Key=prefix
    )
except Exception as e:
    print(f"Error reading key {prefix} from bucket {os.environ['BUCKET']}: {e}")
    print(response)
content = response['Body'].read()
return send_file(
    io.BytesIO(content),
    mimetype=doc.mimetype,
    download_name="test.pdf",
    as_attachment=False,
)

THE FRONT END

    getDocument(token, i18n.language, _id).then(response => {
        const url = window.URL.createObjectURL(new Blob([response.data], {
            type: response.headers['content-type']
        }));
        const link = document.createElement('a');
        link.href = url;
        link.setAttribute('download', 'file.pdf');
        link.setAttribute('target', '_blank');
        document.body.appendChild(link);
        link.click();
    })

Here is a part of response.data and is type is string : enter image description here

Any idea to solve it?

bmagnette
  • 70
  • 2
  • 10

0 Answers0