Allow public download (rather than file open) from R2

I have an R2 bucket set up with .ZWO files stored. I have mapped a custom domain and have no problem accessing the files publically using the custom domain and file name.

I am trying to allow users to download (rather than open the files) and have used the download attribute on the button url but the files are still being opened by the browser.

ChatGPT has suggested “set the Content-Type header to application/octet-stream for .zwo files.” but it gets a bit hazy as to how that is achieved and I’ve not been able to find instructions on this forum.

Any assistance appreciated.


That would be with a Transform Rule for Response Headers:

1 Like

Thanks for the advice. Unfortunately it looks like Cloudflare doesn’t allow the Content Type header to be set.

The usual way to force a browser to download rather than open a file is by setting a Content-Disposition header to attachment

1 Like

I’m not sure why you say that. The screenshot is of a functioning rule. Here’s a file in my R2 Bucket where that rule exists:

You’d get that error if you try to set it on a Modify Request Header rule instead of a Modify Response Header rule (3rd tab). Make sure you’re trying to create the right one.

Magic Link to create Modify Response Header Transform Rule:


Thank you everyone.

@Chaika - correct I was making that mistake.

@sdayman - thank you, your solution worked once I deployed it correctly.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.