1 month ago

Saving blob image in laravel's controller

Posted 1 month ago by mstdmstd

Hello! In my Laravel 5/vuejs 2.6 I upload image with vue-upload-component and sending requested image blob I try to save it with controller code like :

            if ( !empty($requestData['avatar_filename']) and !empty($requestData['avatar_blob']) ) {
                $dest_image = 'public/' . Customer::getUserAvatarPath($newCustomer->id, $requestData['avatar_filename']);

                $requestData['avatar_blob']= str_replace('blob:','',$requestData['avatar_blob']);
                Storage::disk('local')->put($dest_image, file_get_contents($requestData['avatar_blob']));
                ImageOptimizer::optimize( storage_path().'/app/'.$dest_image, null );
            } // if ( !empty($page_content_image) ) {

As result I have image uploaded, but it is not readable. Source file has 5 Kib, then resulting file has 5.8 Kib and in browser's console I see blobs path as avatar_blob: "blob:"

Have I to convert my blob some how to save it correctly?


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