My application uploads images to s3. I use front-end rendering to get the colors of the image, but because uploading to s3 lowers the quality (jpeg'ish), I get more colors then desired.
$s3 = \Storage::disk('s3');
$s3->put('/images/file.jpg', '/images/file.jpg', 'public');
Is there way to prevent this quality loss? I noticed that if I upload the file directly using aws console website, the quality stays the same which is ideal.
Thank you!
Individual Amazon S3 objects can range in size from a minimum of 0 bytes to a maximum of 5 TB. The largest object that can be uploaded in a single PUT is 5 GB. For objects larger than 100 MB, customers should consider using the Multipart Upload capability.
Uploading Individual Files to S3 When you upload files to S3, you can upload one file at a time, or by uploading multiple files and folders recursively.
In the controller Action
public function uploadFileToS3(Request $request)
{
$image = $request->file('image');
}
Next we need to assign a file name to the uploaded file.You could leave this as the original filename, but in most cases you will want to change it to keep things consistent. Let’s change it to a timestamp, and append the file extension to it.
$imageFileName = time() . '.' . $image->getClientOriginalExtension();
Now get the image content as follows
$s3 = \Storage::disk('s3');
$filePath = '/images/file.jpg' . $imageFileName;
$s3->put($filePath, file_get_contents($image), 'public');
For further info you can refer to this
I am not familiar with Laravel but i am familiar with AWS S3, and i'm using aws-sdk-php.
As far as i know, neither AWS S3 nor php-sdk don't do something implicitly under the hood. So it must be something going wrong elsewhere in your project.
You can try use plain aws-sdk-php:
$s3 = S3Client::factory([
'region' => 'us-west-2',
'credentials' => $credentials,
'version' => 'latest',
]);
$s3->putObject([
'Bucket' => 'myBucket',
'Key' => 'test/img.jpg',
'SourceFile' => '/tmp/img.jpg',
]);
It works perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With