Search code examples
laravellaravel-storage

How to upload file from my local storage into S3?


Looking at some samples how Laravel work with AWS S3 survice I see examples of code like :

$path = $request->file('image')->store('images', 's3');

But when I try to upload file from my local storage :

   $adImageDestDirectory = '/public/' .  ‘subdirectory_path’;

  $path = Storage::get($adImageDestDirectory . $adImageItem->image)->store('images', 's3');

I got error:

Call to a member function store() on string

Which is valid way ?

Thanks!


Solution

  • If you need to upload files from local storage to aws S3 bucket then you need to copy files from local: use function file_get_contents()

    Storage::disk('s3')->put('filename.jpg', file_get_contents($adImageDestDirectory );