0

I would like to store json file in google storage. To save storage and network bandwidth, the file is compressed in gzip format and upload to my bucket, and set Caches-Control: no-transform to prevent Transcoding. The problem is the file stored in google storage is in decompressed format (json), and the Cache-Control in object metadata is empty. My code:

const admin = await import("firebase-admin");
  const bucket = admin.storage().bucket();
  const file = bucket.file(path);
  await file.save(JSON.stringify(jsonArray), 
    {'gzip': true, 'contentType':'application/json',
      'metadata': {
        'Cache-Control': 'no-transform'}})

The object metadata: Content-Encoding: gzip, Content-Type: application/json. File size in google storage: 10.8kb. I manually set Cache-Control: no-transform, and use postmant & Firebase_storage plugin for flutter to download content, and I always receives content in text format – What am I missing here?

bigbang489
  • 21
  • 4
  • How can you say that the file isn't compressed on Cloud Storage? Can you share the content encoding of the object on Cloud Storage? – guillaume blaquiere Jul 03 '21 at 16:53
  • Firebase requires that files are large enough to be compressed. I think the minimum size is 1024 bytes. What are the sizes of your uploads? – John Hanley Jul 03 '21 at 18:47
  • I found this answer regarding compressing small files: https://stackoverflow.com/a/47962022/8016720 – John Hanley Jul 03 '21 at 18:51
  • This is the object metadata: Content-Encoding: gzip Content-Type: application/json My file size in google storage is: 10.8k, I manually set Cache-Control: no-transform, and use postmant & Firebase_storage plugin for flutter to download content, and I always receives content in text format – bigbang489 Jul 04 '21 at 03:34

0 Answers0