b2-sdk-python icon indicating copy to clipboard operation
b2-sdk-python copied to clipboard

How to set cache-control header when using upload_local_file

Open djbloc opened this issue 2 years ago • 1 comments

How do you set the X-Bz-Info-b2-cache-control HTTP header documented here using the upload_local_file function?

I've tried to set via file_infos attribute using file_infos={"Cache-Control": "max-age=86400"} with no success.

On testing using HEAD request to S3 URL returns

HTTP/1.1 200 Accept-Ranges: bytes Last-Modified: Fri, 23 Sep 2022 18:38:23 GMT ETag: "079880d5addca95fa9846fa5033d72e1" x-amz-meta-cache-control: max-age=86400 x-amz-request-id: 2a415cc03ebeade2 x-amz-id-2: aMSlmgTPFZkBlojSzNYUznDk/Ym0w2TXK x-amz-version-id: redacted Content-Type: video/mp2t Content-Length: 268088 Date: Fri, 23 Sep 2022 18:40:19 GMT

On testing using HEAD request to Friendly URL returns

HTTP/1.1 200 x-bz-file-name: redacted x-bz-file-id: redacted x-bz-content-sha1: 4251cdc9aaa9e22c76d5191004431b84e10ed773 X-Bz-Upload-Timestamp: 1663958303158 Accept-Ranges: bytes x-bz-info-cache-control: max-age=86400 Content-Type: video/mp2t Content-Length: 268088 Date: Fri, 23 Sep 2022 18:41:08 GMT

Note that neither approach returns a native "Cache-Control" HTTP header

djbloc avatar Sep 23 '22 19:09 djbloc

As documentation of Bucket.upload_local_file shows, this is not implemented in b2-sdk-python yet. It seems that implementing it would just involve passing a parameter in a couple of places + two tests that would make sure this feature keeps working and is not broken by some future change. Would you like to take a stab at contributing a pull request to add it? b2-sdk-python developers provide quite a lot of support for contributors and you can learn quite a bit when working on it.

ppolewicz avatar Sep 24 '22 09:09 ppolewicz

I have a similar problem. I want to add the {Content-Disposition: 'attachment;'} to the response header so that resources won't display inline in the browser, but I cannot for the life of me seem to find anything useful. I might just have to use Firebase

israel-oye avatar Mar 25 '23 12:03 israel-oye

The CLI currently doesn't support setting Content-Disposition and b2-sdk-python also doesn't support it, so it'll need to be added in both places along with other missing parameters listed here.

ppolewicz avatar Mar 28 '23 17:03 ppolewicz