mstdmstd
2 months ago
146
2
Vue

Saving blob image in laravel's controller

Posted 2 months 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:http://local-hostels2.com/91a18493-36a7-4023-8ced-f5ea4a3c58af"

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

Thanks!

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