skip to Main Content

This may seem like a question similar to others, but the focus is that it is a .doc file.

I am working with Python to generate AWS s3 pre-signed urls that looks like this:

def generate_s3_presigned_url(self, filename, expiration=300):
    try:
        mime_type = mimetypes.guess_type(filename)[0]
        # Generate the presigned URL
        presigned_url = self.client.generate_presigned_url(
                ClientMethod="get_object",
                Params={
                    "Bucket": self.bucket_name,
                    "Key": filename,
                    'ResponseContentType': mime_type,
                    'ResponseContentDisposition': 'inline',
                },
            ExpiresIn=expiration,  # Expiration time in seconds (300 seconds = 5 minutes)
            )

        return presigned_url

In this occasion I am working with Microsoft Word files, so the part 'ResponseContentType': mime_type is actually 'ResponseContentType': 'application/msword’.

Apparently, by adding the 'ResponseContentDisposition': ‘inline’ it was supposed to work but it didn’t.

When I am using the generated url the doc file keeps being downloaded no matter what I tried, but what I am trying to achieve is to display the doc file on my browser.
What can I do?

2

Answers


  1. If Content-Disposition is set to inline, the browser will attempt to render the content as a web page or as part of the web page.

    That works for supported files like PDFs, but as far as I know, no browser supports displaying a .doc / .docx (Microsoft Word document) in the browser itself.

    The browser then defaults to downloading the file; there’s nothing you can do and this isn’t related to the fact that you’re using pre-signed URLs or AWS S3.

    Login or Signup to reply.
  2. If your docx is on Amazon AWS S3 then you can use "Microsoft Online" Office viewer which has lots of nice features such as translation.

    Here is an example, courtesy of PDFTron (Other samples may be available) use as one line.

    https://view.officeapps.live.com/op/view.aspx?
    src=https%3A%2F%2Fpdftron.s3.amazonaws.com%2Fdownloads%2Fpl%2FQuote_.Word.docx
    &wdOrigin=BROWSELINK

    https://view.officeapps.live.com/op/view.aspx?src=https%3A%2F%2Fpdftron.s3.amazonaws.com%2Fdownloads%2Fpl%2FQuote_.Word.docx&wdOrigin=BROWSELINK

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search