【发布时间】:2018-10-10 07:36:42
【问题描述】:
我有以下脚本可以处理小文件,但是当我尝试大文件 (4GB) 时失败:
<?php
require 'vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;
$storage = new StorageClient([
'keyFilePath' => 'keyfile.json',
'projectId' => 'storage-123456'
]);
$bucket = $storage->bucket('my-bucket');
$options = [
'resumable' => true,
'chunkSize' => 200000,
'predefinedAcl' => 'publicRead'
];
// Upload a file to the bucket.
$bucket->upload(
fopen('data/file.imgc', 'r'),
$options
);
?>
我收到的错误是:
Fatal error: Uncaught exception 'Google\Cloud\Core\Exception\GoogleException' with message 'Upload failed. Please use this URI to resume your upload:
知道如何上传大文件吗?
我也试过 getResumableUploader():
$uploader = $bucket->getResumableUploader(fopen('data/file.imgc', 'r'), [
'name' => 'file.imgc'
]);
try {
$object = $uploader->upload();
} catch (GoogleException $ex) {
$resumeUri = $uploader->getResumeUri();
$object = $uploader->resume($resumeUri);
}
当导航到恢复 URI 时,它会返回“不允许的方法”
【问题讨论】:
-
这可以通过this package分块上传文件来完成。示例项目 - github.com/pionl/laravel-chunk-upload-example
标签: php google-cloud-platform google-cloud-storage