upload file to firebase storage laravel

Solutions on MaxInterview for upload file to firebase storage laravel by the best coders in the world

showing results for - "upload file to firebase storage laravel"
Emilio
27 May 2018
1 $image = $request->image; //base64 string from frontend  
2 $student   = app('firebase.firestore')->database()->collection('Student')->document('defT5uT7SDu9K5RFtIdl');  
3 $firebase_storage_path = 'Students/';  
4 $name     = $student->id();  
5 $localfolder = public_path('firebase-temp-uploads') .'/';  
6 if (!file_exists($localfolder)) {  
7     mkdir($localfolder, 0777, true);  
8 }  
9 $parts = explode(";base64,", $image);  
10 $type_aux = explode("image/", $parts[0]);  
11 $type = $aux[1];  
12 $base64 = base64_decode($parts[1]);  
13 $file = $name . '.png';  
14 if (file_put_contents($localfolder . $file, $base64)) {  
15     $uploadedfile = fopen($localfolder . $file, 'r');  
16     app('firebase.storage')->getBucket()->upload($uploadedfile, ['name' => $firebase_storage_path . $name]);  
17     //will remove from local laravel folder  
18     unlink($localfolder . $file);  
19     echo 'success';  
20 } else {  
21     echo 'error';  
22 }  
23