问题描述
如何正确设置 fopen?由于我不知道初始文件位置,因此在尝试上传时出现 500 错误。
- 我需要使用分段上传来优化传输速度。
- 我的网站将是无服务器的,将在 Vapor 上运行,因此在上传到 S3 之前我无法将文件保存到本地。
- 我想将文件流式上传到 S3 存储桶,文件是使用表单选择的,但我不知道它们在客户端计算机上的初始本地路径...AWS 文档上显示了一些替代方案,但他们都假设您将已经知道文件的初始位置...
$s3Client = new S3Client([
'profile' => 'default','region' => 'us-east-2','version' => 'latest'
]);
$bucket = 'your-bucket';
$key = 'my-file.zip';
// Using stream instead of file path
$source = fopen('/path/to/large/file.zip','rb');
$uploader = new ObjectUploader(
$s3Client,$bucket,$key,$source
);
do {
try {
$result = $uploader->upload();
if ($result["@Metadata"]["statusCode"] == '200') {
print('<p>File successfully uploaded to ' . $result["ObjectURL"] . '.</p>');
}
print($result);
} catch (MultipartUploadException $e) {
rewind($source);
$uploader = new MultipartUploader($s3Client,$source,[
'state' => $e->getState(),]);
}
} while (!isset($result));
fclose($source);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)