Image Intervention + S3 = weirdness HELP! :(

Published 3 months ago by shinigaimi

I am attempting to Upload a resized image via Image Intervention, does not work! says success but uploads a folder with no extension

Here is code that does not work!

//Global directory in S3
        $file_path = '' . Auth::User()->comp_id . '/' . $request->prop_id . '/' . $request->page_id . '/pictures/';
foreach ($request->image_upload as $image) {
                //  DRIVERS LICENSE UPLOAD
                // PUTS PICTURES IN USERS FOLDER UNDER "PICTURES FOLDER"


                $image_regular = Image::make($image)->resize($width, $height, function ($constraint) {
                    $constraint->aspectRatio();
                    $constraint->upsize();
                })->orientate();
                $image_upload  = $image_regular->stream();

                //      Upload to AWS with no file resizing
                Storage::disk('s3')->put($file_path, $image_upload->__string(), 'public');
                dd('uploaded to S3');
}

When it uploads it looks like this ->https://imgur.com/a/iG5EeSK

I am able to upload to S3 normally using the code below, this works perfectly fine but I want to resize to a smaller size as you can upload LARGE pictures and I want to create smaller 200x200 thumbnails so the page loads quicker!

            foreach ($request->image_upload as $image) {
                // PUTS PICTURES IN USERS FOLDER UNDER "PICTURES FOLDER"

                //      Upload to AWS with no file resizing
                Storage::disk('s3')->put($file_path, $image, 'public');
                dd('upload to S3');
}
Best Answer (As Selected By shinigaimi)
shinigaimi

I Found a workaround, first saving locally and pulled the locally stored image to S3 and Deleting from local after upload


            foreach ($request->image_upload as $image) {

                //      Store Image with random name
                $path         = $image->store('');
                $get_doc_name = explode('/', $path);

                //
                //  Upload Max File size specified above
                //
                $img_full = Image::make(storage_path('app/documents/' . $get_doc_name[0]));

                $img_full->height() > $img_full->width() ? $width = null : $height = null;
                $img_full->resize($width, $height, function ($constraint) {
                    $constraint->aspectRatio();
                    $constraint->upsize();
                })->orientate();
                //      Replace + Upload re-sized thumbnails to local disk
                $img_full->save(storage_path('app/documents/' . $get_doc_name[0]));
                //      Send Uploaded Image to S3 with unique name
                $name    = Storage::disk('s3')->putFile($file_path, new File(storage_path('app/documents/' . $get_doc_name[0])), 'public');
                $getName = explode('/', $name); //      Default is $getName[6] for image name

//      Delete Thumbnail locally after Upload to S3
                unlink(storage_path('app/documents/' . $get_doc_name[0]));
}

shinigaimi

I Found a workaround, first saving locally and pulled the locally stored image to S3 and Deleting from local after upload


            foreach ($request->image_upload as $image) {

                //      Store Image with random name
                $path         = $image->store('');
                $get_doc_name = explode('/', $path);

                //
                //  Upload Max File size specified above
                //
                $img_full = Image::make(storage_path('app/documents/' . $get_doc_name[0]));

                $img_full->height() > $img_full->width() ? $width = null : $height = null;
                $img_full->resize($width, $height, function ($constraint) {
                    $constraint->aspectRatio();
                    $constraint->upsize();
                })->orientate();
                //      Replace + Upload re-sized thumbnails to local disk
                $img_full->save(storage_path('app/documents/' . $get_doc_name[0]));
                //      Send Uploaded Image to S3 with unique name
                $name    = Storage::disk('s3')->putFile($file_path, new File(storage_path('app/documents/' . $get_doc_name[0])), 'public');
                $getName = explode('/', $name); //      Default is $getName[6] for image name

//      Delete Thumbnail locally after Upload to S3
                unlink(storage_path('app/documents/' . $get_doc_name[0]));
}

Please sign in or create an account to participate in this conversation.