Hosting Static PDF Files in Cloud Storage for Direct Browser Display

Configure Cloud Storage for Direct Display of PDF Files

Question

You host a static website on Cloud Storage.

Recently, you began to include links to PDF files on this site.

Currently, when users click on the links to these PDF files, their browsers prompt them to save the file onto their local system.

Instead, you want the clicked PDF files to be displayed within the browser window directly, without prompting the user to save the file locally.

What should you do?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

C.

To display PDF files within the browser window directly without prompting users to save the file locally, you should set the Content-Type metadata of the PDF file objects to application/pdf. Therefore, the correct answer is option C: Set Content-Type metadata to application/pdf on the PDF file objects.

Here's a detailed explanation for why this is the correct answer:

When a user clicks on a link to a PDF file, the browser sends a request to the server to fetch the file. The server responds with the file content along with metadata about the file. One such metadata is the Content-Type header, which specifies the type of content being sent back to the browser. The browser uses this header to decide how to handle the content.

In the case of PDF files, if the Content-Type header is set to application/pdf, the browser knows that it's a PDF file and can handle it appropriately. By default, most modern browsers have built-in PDF viewers that can display the contents of PDF files directly within the browser window without prompting the user to save the file locally.

Therefore, by setting the Content-Type metadata to application/pdf on the PDF file objects hosted on Cloud Storage, you can instruct the browser to display the PDF files directly within the browser window without prompting the user to save the file locally.

The other options are not relevant to this problem. Enabling Cloud CDN (option A) improves website performance by caching content in edge locations closer to the user, but it does not affect how the browser handles PDF files. Enabling "Share publicly" on the PDF file objects (option B) allows anyone with the link to access the file, but it does not affect how the browser handles PDF files. Adding a label to the storage bucket with a key of Content-Type and value of application/pdf (option D) does not set the Content-Type metadata of the PDF file objects, so it will not affect how the browser handles PDF files.