【问题标题】:Firebase web client gzip upload to Cloud StorageFirebase 网络客户端 gzip 上传到 Cloud Storage
【发布时间】:2020-06-29 23:18:33
【问题描述】:

我正在使用 Firebase 网络客户端,并希望将 gzip 压缩文件上传到 Cloud Storage。使用 Nodejs 客户端,可以简单地将 gzip 指定为一个选项,如下所示:await bucket.upload(filepath, { destination, gzip: true });。是否可以使用 Firebase 网络客户端将数据上传到云存储?例如,我将如何更改以下内容以 gzip 文件?

const ref = firebase.storage().ref().child("test.json");
const blob = new Blob([JSON.stringify({ hello: "world" })], { type: "application/json" });
await ref.put(blob);

【问题讨论】:

    标签: firebase google-cloud-storage gzip firebase-storage


    【解决方案1】:

    您可以看一下documentation,它向您展示了上传图片的示例:

    // Create a root reference
    var storageRef = firebase.storage().ref();
    
    // Create a reference to 'mountains.jpg'
    var mountainsRef = storageRef.child('mountains.jpg');
    
    // Create a reference to 'images/mountains.jpg'
    var mountainImagesRef = storageRef.child('images/mountains.jpg');
    
    // While the file names are the same, the references point to different files
    mountainsRef.name === mountainImagesRef.name            // true
    mountainsRef.fullPath === mountainImagesRef.fullPath    // false
    
    // Create file metadata including the content type
    var metadata = {
    contentType: 'image/jpeg',
    };
    
    // Upload the file and metadata
    var uploadTask = storageRef.child('images/mountains.jpg').put(file, metadata);
    

    但在您的情况下,您可能需要上传 gzip 文件。只需更改元数据。

    【讨论】:

    • 我认为 OP 正在寻找一个如何将他们现有的 JSON 文件上传作为 gzip 的示例(以节省传输带宽)。
    • @FrankvanPuffelen 实际上我不介意它是压缩客户端还是服务器端,我只想确保它在云存储中被压缩以节省成本。目前,我正在将数据发送到 Cloud Function,以便在上传到 Cloud Storage 之前对其进行 gzip 压缩。但如果可能的话,我想再次摆脱云功能,以节省成本。
    猜你喜欢
    • 2020-10-20
    • 2016-06-15
    • 2015-02-21
    • 2019-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    相关资源
    最近更新 更多