Reputation: 3129
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!
Upvotes: 0
Views: 4541
Reputation: 11
You can do this to store the file to s3
$file = $request->file('attachment');
$fileName = time() . $file->getClientOriginalName();
$filePath = 'uploads/' . $fileName;
Storage::disk('s3')->put($filePath, file_get_contents($file), 'public');
$urlPath = Storage::disk('s3')->url($filePath);
Upvotes: 1
Reputation: 2945
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 );
Upvotes: 4