0

In laravel 8 uploading image to AWS S3 and I keep url in db table(I set visibility= 'public', so I can show image in my browser by this saved url. Also I need to get width, height, filesize of this file. When I use Storage in local I use Intervention\Image library with methods :

$file_width  = Image::make($image_path)->width();
$file_height = Image::make($image_path)->height();
$file_size   = Image::make($image_path)->filesize();

where $image_path - is path under my Storage.

With Object URL property my uploaded image has properties S3 URI looking like

   s3://app-s3/subdir/filepath.jpg

and Amazon Resource Name (ARN) :

arn:aws:s3:::app-s3/app-s3/subdir/filepath/31fzgzXsVTL.jpg

How can I to read width, height, filesize of image in s3 ?

MODIFIED BLOCK : Reading at https://laravel.com/docs/8.x/filesystem#file-metadata link example code:

use Illuminate\Support\Facades\Storage;
$size = Storage::size('file.jpg');

I try with get size with ‘s3’ driver:

$image_size = Storage::disk('s3')->size($cloud_url);

I got error :

File not found at path: https:/app-s3.s3.eu-central-1.amazonaws.com/app-s3/subdir/filepath/31fzgzxsvtl.jpg

As $cloud_url is common url, not path ... From the docs looks like 'file.jpg' is PATH of the image in Storage directory. But I am not sure...

Thanks in advance!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Petro Gromovo
  • 1,755
  • 5
  • 33
  • 91
  • 1
    You can use the S3 public URL to open the image. You can get that using [`Storage::url`](https://laravel.com/docs/8.x/filesystem#file-urls) and will result in a URL like e.g. `https://app-s3.s3.amazonaws.com/subdir/filepath.jpg` or something like this – apokryfos Aug 12 '21 at 06:12
  • filesize can be obtained from header, height and width can be obtained via js property from the image url – bhucho Aug 12 '21 at 06:20
  • 1
    https://laravel.com/docs/8.x/filesystem#file-metadata – S N Sharma Aug 12 '21 at 06:33
  • Please look at MODIFIED BLOCK – Petro Gromovo Aug 12 '21 at 07:00
  • @bhucho, please3 ref to such example – Petro Gromovo Aug 12 '21 at 07:00
  • You can send a head request (this will be fastest and lightest as it has no body just headers) or if you want the image then you can send a get request the header `content-length` would have the filesize, for height width see this question https://stackoverflow.com/q/11442712/9471283 – bhucho Aug 12 '21 at 09:22

0 Answers0