Answers for "upload file to firebase storage laravel"

PHP
0

upload file to firebase storage laravel

$image = $request->image; //base64 string from frontend  
 $student   = app('firebase.firestore')->database()->collection('Student')->document('defT5uT7SDu9K5RFtIdl');  
 $firebase_storage_path = 'Students/';  
 $name     = $student->id();  
 $localfolder = public_path('firebase-temp-uploads') .'/';  
 if (!file_exists($localfolder)) {  
     mkdir($localfolder, 0777, true);  
 }  
 $parts = explode(";base64,", $image);  
 $type_aux = explode("image/", $parts[0]);  
 $type = $aux[1];  
 $base64 = base64_decode($parts[1]);  
 $file = $name . '.png';  
 if (file_put_contents($localfolder . $file, $base64)) {  
     $uploadedfile = fopen($localfolder . $file, 'r');  
     app('firebase.storage')->getBucket()->upload($uploadedfile, ['name' => $firebase_storage_path . $name]);  
     //will remove from local laravel folder  
     unlink($localfolder . $file);  
     echo 'success';  
 } else {  
     echo 'error';  
 }
Posted by: Guest on April-11-2021

Code answers related to "upload file to firebase storage laravel"

Browse Popular Code Answers by Language