Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compress image file which is private in AWS s3 #1311

Closed
sajadshouli opened this issue Mar 6, 2024 · 1 comment
Closed

compress image file which is private in AWS s3 #1311

sajadshouli opened this issue Mar 6, 2024 · 1 comment

Comments

@sajadshouli
Copy link

before I change my filesystem from local to s3 I have a command which compresses the image size like this

           $image = Image::make($media->file);
  
  
            $fullPath = $media->file; // in local filesystem was like this. https://domain.com/storage/foobar.png
            
            if ($media->disk != 's3') {
                $filePath = str_replace('/storage', 'public', parse_url($media->file, PHP_URL_PATH));
                $fullPath = storage_path('app/' . $filePath);
            }
            
           $image->save($fullPath, 70);

in local or public filesystems the code works fine but when I changed the filesystem to s3, It could not compress the file since the file path will be something like this

https://{domain}/materials/1709755329jhgqfomuio-zorat.png?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=99120f29-11e6-4c3a-aa0a-e62e5241025e%2F20240306%2Fsimin%2Fs3%2Faws4_request&X-Amz-Date=20240306T203008Z&X-Amz-SignedHeaders=host&X-Amz-Expires=1860&X-Amz-Signature=d3e5f4b11d06d6503ae8e5f17cfdcf22e55a515c06462c4f971b5a443c653dc0

and the error is like this

  Encoding format (png?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=99120f29-11e6-4c3a-aa0a-e62e5241025e%2F20240306%2Fsimin%2Fs3%2Faws4_request&X-Amz-Date=20240306T204408Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3360&X-Amz-Signature=b10e0ce0908d6c8944217caa971355b84d807c44ce0a9f75b881d903f197984b) is not supported.

in this situation does the package can compress the file with other method or something else

@olivervogel
Copy link
Member

olivervogel commented Mar 7, 2024

I would not use the save() method here to transfer files to remote data storage, as it is primarily designed for the local file system.

I would use one of the encoder methods to get the raw image data. Then you can do what you want with it: See #431 (comment). Data compression and transfer to S3 is not part of this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants