TLDR
Goal: Download file without decompressive transcoding from a bucket in GCP. Scenario
- Metadata is set as per documentation (cache-control set to
no-transform, content-encoding togzip, content type toapplication/json
What I did
- Doing the curl command only with no-transform in cache control (metadata of the stored file) doesn't work
- Doing the curl command with header Accept-Encoding works
Conclusion: Need to send Accept-Encoding header
Problem: The Node.js client for GCP in their File.download method doesn't seem to have a way to change the headers of the request.
Old Question
I have stored a gzip file in a bucket. The metadata of this file is:
Content-type: application/json
Content-encoding: gzip
Cache-control: no-transform
As per their documentation:
When an object meets these two criteria, it undergoes decompressive transcoding when served, and the response containing the object does not contain a
Content-EncodingorContent-Lengthheader.There are two ways to prevent decompressive transcoding from occurring for an object that is otherwise eligible:
If the request for the object includes an
Accept-Encoding: gzipheader, the object is served as-is in that specific request, along with aContent-Encoding: gzipresponse header.If the
Cache-Controlmetadata field for the object is set tono-transform, the object is served as a compressed object in all subsequent requests, regardless of anyAccept-Encodingrequest headers.
The no-transform should prevent that when downloading the decompressive transcoding take place. It does, so I tried solution one that is sending Accept-Encoding: gzip which works great with my curl command.
However, I'm using the Node.js client library File.download method which apparently seems to ignore everything and worst of all I can't find how to adapt the headers of this call.
Code
import { Storage, File, Bucket, CopyOptions, GetAclResponse } from '@google-cloud/storage'
export const downloadFile = async (file: File, destination: string)=>{
try {
await file.download({destination})
} catch {
// something
}
}
Does anyone know how to do it using the client library?
Thank you, very much
Tried adding
no-transformLooked for the documentation, no success