N
N
Nubbb2021-02-10 15:54:49
Amazon Web Services
Nubbb, 2021-02-10 15:54:49

How to save photo on s3 in Larael?

there is such a code

$file = $request->file('image');

            $avatar = Image::make($file);
            $avatar->resize(280, 280, function ($constraint) {
                $constraint->aspectRatio();
            });

            $filename = $file->getClientOriginalName();
            $mime = $file->getClientOriginalExtension();
            $filename = md5(time() . $filename) . '.' . $mime;

            $new_path = env('STORAGE_SHOP_AVATAR');

            $avatar->save(Storage::disk('s3')->path($new_path . $filename),  $avatar->filesize() > 200000 ? 80 : null);


when saved gives

code: 500
error: true
message: "Can't write image data to path (webassets/shops/avatar/c9c9243b028d6ee91efd2a80a0568d6e.png)"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nubbb, 2021-02-10
@Nubbb

did so

$file = $request->file('image');

            $avatar = Image::make($file);
            $avatar->resize(280, 280, function ($constraint) {
                $constraint->aspectRatio();
            })->encode(null, $avatar->filesize() > 200000 ? 80 : null);

            $filename = $file->getClientOriginalName();
            $mime = $file->getClientOriginalExtension();
            $filename = md5(time() . $filename) . '.' . $mime;

            Storage::disk('s3')->put($path . $filename, $avatar);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question