Download file from GCP bucket without using decompressive transcoding by default

32 Views Asked by At

TLDR

Goal: Download file without decompressive transcoding from a bucket in GCP. Scenario

  1. Metadata is set as per documentation (cache-control set to no-transform, content-encoding to gzip, content type to application/json

What I did

  1. Doing the curl command only with no-transform in cache control (metadata of the stored file) doesn't work
  2. 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-Encoding or Content-Length header.

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: gzip header, the object is served as-is in that specific request, along with a Content-Encoding: gzip response header.

  • If the Cache-Control metadata field for the object is set to no-transform, the object is served as a compressed object in all subsequent requests, regardless of any Accept-Encoding request 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-transform

  • Looked for the documentation, no success

0

There are 0 best solutions below