Laravel 5: How do you copy a local file to Amazon S3?

后端 未结 6 2097
心在旅途
心在旅途 2021-02-08 11:53

I\'m writing code in Laravel 5 to periodically backup a MySQL database. My code thus far looks like this:

    $filename = \'database_backup_\'.date(\'G_a_m_d_y\         


        
6条回答
  •  情书的邮戳
    2021-02-08 12:38

    Laravel has now putFile and putFileAs method to allow stream of file.

    Automatic Streaming

    If you would like Laravel to automatically manage streaming a given file to your storage location, you may use the putFile or putFileAs method. This method accepts either a Illuminate\Http\File or Illuminate\Http\UploadedFile instance and will automatically stream the file to your desired location:

    use Illuminate\Http\File;
    use Illuminate\Support\Facades\Storage;
    
    // Automatically generate a unique ID for file name...
    Storage::putFile('photos', new File('/path/to/photo'));
    
    // Manually specify a file name...
    Storage::putFileAs('photos', new File('/path/to/photo'), 'photo.jpg');
    

    Link to doc: https://laravel.com/docs/5.8/filesystem (Automatic Streaming)

    Hope it helps

提交回复
热议问题