Laravel 将大文件上传到外部磁盘 (S3) 时出现问题

Laravel issue uploading large files to external disk (S3)

我在将大小约为 400MB 的文件上传到 Laravel 中的外部磁盘时遇到问题。 在本地磁盘上存储上传的文件没有问题,但是当需要将其上传到 S3 磁盘时,出现以下错误:

ErrorException: fwrite(): Unable to create temporary file, Check permissions in temporary files directory.

使用以下代码(没有错误):

$contents = file_get_contents($file);
$local = \Storage::disk('local');
$local->put($desitinationUrl,  $contents);

但是当发生以下情况时我得到一个错误

$uploadedfile = \Storage::disk('local')->get($destinationUrl);
$s3 = \Storage::disk('s3');
$s3->put($destinationUrl,  $uploadedfile);

有人知道问题出在哪里吗? 提前致谢!

您可以尝试边读边写流:

Storage::disk('s3')
  ->writeStream(
      $destinationUrl, 
      Storage::disk('local')->readStream($destinationUrl)
  );