'How to retrieve image's name to store in image table after uploading on AWS S3 using Laravel?
I am uploading images on AWS S3 using laravel8 and package (league/flysystem-aws-s3-v3) with following code.
$image = $request->file('image');
$data['image_name'] = time().'.'.$image->getClientOriginalExtension();
$data['path'] = Storage::disk('s3')->put('images', $request->image);
$data['ab'] = Storage::disk('s3')->url($data['path']);
return $data;
After successful upload, Above code is returing
{
"image_name": "1644919540.jpg",
"path": "images/SYrPZTqDQgSuIvqBZzdrSX5JEmRQhwEC3muYDvJO.jpg",
"ab": "https://abc-user-images.s3.ap-south-1.amazonaws.com/images/SYrPZTqDQgSuIvqBZzdrSX5JEmRQhwEC3muYDvJO.jpg"
}
I need to retrieve only the image's name in the path variable like
"path":"SYrPZTqDQgSuIvqBZzdrSX5JEmRQhwEC3muYDvJO.jpg"
Solution 1:[1]
$image_data['image_n'] = Str::of($data['path'])->substr(7); is also working.
this is returning the exact image name.
{
"image_name":"SYrPZTqDQgSuIvqBZzdrSX5JEmRQhwEC3muYDvJO.jpg"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
