如何在谷歌云存储上上传多个文件,例如批量插入 [英] how to upload multiple files like a bulk insert on google cloud storage

查看:754
本文介绍了如何在谷歌云存储上上传多个文件,例如批量插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况.我正在使用laravel和Google Cloud Storage,因此基本上,我将自己的自定义文件系统附加到Google Cloud Storage.我的代码看起来像这样-

try{
    $disk = Storage::disk('gcs');

                $disk->put('/service_provider/transports/tech_passports', $file1);
                $disk->put('/service_provider/transports/tech_passports', $file2);

                $disk->put('/service_provider/transports/pictures', $file3);
                $disk->put('/service_provider/transports/pictures', $file4);
                $disk->put('/service_provider/transports/pictures', $file5);
                $disk->put('/service_provider/transports/pictures', $file6);
    } catch(\Exception $e){

}

现在我很担心.如果前三个文件被上传而第四个文件有错误怎么办.所以它会赶上块,最后,只有3个文件将被上传,这不是我所需要的.

我需要的是像原子性一样全部上传或没有任何文件上传.我该如何实现?

解决方案

为确保所有文件都已上传,请尝试使用 Google Cloud Storage API PHP可恢复行为在示例中来自StackOverflow上的另一个问题.

请注意, Cloud SDK实用程序Gsutil 中也实现了可恢复的上传.可以用于同步两个存储桶的内容/目录. /p>


I have the following situation. I'm using laravel and google cloud storage so basically, I have my own custom filesystem attached to google cloud storage. My code looks like this -

try{
    $disk = Storage::disk('gcs');

                $disk->put('/service_provider/transports/tech_passports', $file1);
                $disk->put('/service_provider/transports/tech_passports', $file2);

                $disk->put('/service_provider/transports/pictures', $file3);
                $disk->put('/service_provider/transports/pictures', $file4);
                $disk->put('/service_provider/transports/pictures', $file5);
                $disk->put('/service_provider/transports/pictures', $file6);
    } catch(\Exception $e){

}

Now i'm worried. what if the first three files get uploaded and the fourth one has an error. so it will go to catch block and finally, only 3 files will be uploaded which is not what I need.

What I need is all get uploaded or no file gets uploaded just like atomicity. how do I achieve that?

解决方案

To be sure that all your files get uploaded, try using resumable uploads on each of your individual files, with the following steps:

Initiate upload > Process response > Upload The file > Check Upload Status > Process response > Resume the upload

Retry last three steps to resume upload as many times as necessary or implement another solution (for example: delete all files already uploaded), if it is what you need in your application.

You can also check Google Cloud Storage API PHP resumable behavior in the example from another question on StackOverflow.

Please note that also Cloud SDK utility Gsutil has resumable upload implemented in it. It can be used to Synchronize content of two buckets/directories.


这篇关于如何在谷歌云存储上上传多个文件,例如批量插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆