简体   繁体   English

GCP Cloud Storage 上传文件 SaveOptions onUploadProgress 只回调一次

[英]GCP Cloud Storage upload file SaveOptions onUploadProgress only callback one time

I am trying to get the progress when I upload file to GCP cloud storage by Node.js.当我通过 Node.js 将文件上传到 GCP 云存储时,我试图获得进度。 I found there is an onUploadProgress in SaveOptions, but this is only callback one time.我发现SaveOptions中有一个onUploadProgress,但这只是回调一次。

        storage.bucket(bucket_name).file(file_path).save(buffers, {
                onUploadProgress: (progressEvent) => {
                    console.log(progressEvent)
                }
            }
        )

And the progressEvent value is like below, and bytesWritten's value is the file size.而progressEvent的值如下,bytesWritten的值为文件大小。

{ bytesWritten: 80248835, contentLength: '*' }

Is it possible to get the realtime upload progress event from Node.js client library?是否可以从 Node.js 客户端库获取实时上传进度事件? (@google-cloud/storage) (@谷歌云/存储)

Thank you.谢谢你。

I can received many times callback after I add chunkSize.添加 chunkSize 后,我可以收到多次回调。

const chunkSize = 8 * 1024 * 1024;
storage.bucket(bucket_name).file(file_path).save(buffers, { chunkSize: chunkSize,
        onUploadProgress: (progressEvent) => {
            console.log(progressEvent)
        }
    }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM