How to create Zip and upload files to it on google storage?

Viewed 1702

Using NodeJs v12, We have multiple files creating dynamically for every minute, these files should be uploaded to cloud storage as zip, and this zip files should be updated with new files which are created on my system.

I have referred some docs, it says there is no directory concept in GCS, then how can we archive it?, We have observed that gzip added for files/object.

using @google-cloud/storage latest.

Current code:

storage.bucket(bucketName).upload(destinationStorage, {
     gzip: true,
     destination: userId+"/"+filename,
     metadata: {
         cacheControl: 'no-cache'    
     },
}).then( async(result) =>{
     console.log("Uploaded");
})
1 Answers

In GCS, you can only create, read and delete object. It's not a file system. You can't move (even if you have the option, it's only a create elsewhere and delete the origin) and you can't update the content (you can create a new version if you activate the versioning, but you can't change an existing content)

So, now you understand that you can't update an existing zip to add a file in it. You have to upload it again, with the whole content.

About ZIP and GZIP. It's 2 different things that you don't have to mix up. GZIP compresses only 1 file, ZIP compress files AND can create a package with 1 or several files/folders in it.

So you can't add several files into GZIP, only in ZIP. And ZIP isn't native to GCS, you have to handle the ZIP compression/file management on your side before sending the blob to GCS.

Anyway, I have the feeling that I have cleared up some misunderstood parts but not solved your issues. Don't hesitate to comment if you want more help!

Related