When I open up the files that are in my bucket (for example, the Readme file from the last lab that I downloaded, and then uploaded into this bucket), instead of seeing the file as a text document in my browser in a new tab, the file downloads again onto my computer. When I open up a pdf that I uploaded to my bucket it is the same situation, it downloads onto my computer instead of opening the file in a new tab on my browser.
I’m trying to think about the mental model for the data that’s flowing in this situation but I can’t understand it. Can anyone explain why the files might be downloading to my computer from the bucket instead of opening up in my web browser?
In general, browsers will try to detect the MIME type of an object (set by metadata "Content-Type") to decide what do to with it. If an object has an undetermined/unknown MIME type to the browser, it will simply download that object as "regular file", rather than processing it (open, play, etc.).
So depends on your objects, you need to set their MIME accordingly. For example:
PDF objects need to have MIME type as
application/pdfso that browsers can open them directly.
Regular text objects need to have MIME type as
text/plainso browsers can display it without downloading.
You can use either the Console or gsutil to set the metadata for objects in bucket. Here’s an example with gsutil for PDF file:
gsutil setmeta -h "Content-Type:application/pdf" gs://my-example-bucket/my-document.pdf