wavrik
wavrik

Reputation: 451

How store image on Firebase with Angular 7 front-end and Laravel back-end?

I'm a little confused about Firebase. I have an application that is working fine with the default storage from Laravel. But I don't want any more content generated by my user to be on my server, so I'm thinking of using Firebase Cloud Storage Service. But I'm having some doubts.

This is my controller function that uploads to my server on Laravel when I receive an image file:

  if($request->hasFile('file')) {

                $mpFile = $request->file('file');
                $date  = Carbon::now();
                $year  = $date->year;
                $month = $date->month;
                $directory = $year . '/' . $month;

                $fileObj['filepath'] = Storage::disk('uploads')->put($directory,  $mpFile);
                $fileObj['fileName'] = basename($fileObj['filepath']);
                $exists   = Storage::disk('uploads')->exists($fileObj['filepath']);

                if($exists) {
                    $this->mdFile->store($fileObj, $categoryObj->mp_category_id);
                    $response["imgstatus"] = "Imagem anexada com sucesso";
                }else {
                    $response["imgstatus"] = "Não foi possível fazer o upload tente novamente";
                }

            }

When this happens I store in my database the file_path and file_name in association with the object ID reference on my database.

But I don't know how I will do this with Firebase, I must use Firebase on Laravel? to store the image and receive the file_path and file_name from Firebase? How I do this?

Or is it just another approach?

Upvotes: 0

Views: 208

Answers (1)

Chamika
Chamika

Reputation: 167

Check this documentation https://firebase.google.com/docs/storage/web/upload-files

You can upload images to firebase storage and get the download URL in return. You can save this path in the database you use.

There is nice tutorial in this link: https://angularfirebase.com/lessons/firebase-storage-with-angularfire-dropzone-file-uploader/

Upvotes: 1

Related Questions