Search code examples
laravelamazon-s3php-7plesk

Laravel issue uploading large files to external disk (S3)


I'm having issues uploading files with the size of about 400MB to an external disk in Laravel. On the local disk I have no issues storing the uploaded file but when it needs to be uploaded to the S3 disk I get the following error:

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

The following code is used (which gives no errors):

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

But when the following happens I get an error

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

Does anyone know where the issue may be? Thanks in advance!


Solution

  • You could try directly writing the stream as you read it:

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