2

I am looking around to find a way on how to be able to upload multiple images/files to Firebase Storage using functions but I am not able to find any example. Actually I found an similar example but the the files limit is only 10mb and that is not enough for my case where user can post up to 15HD images.

I am looking forward just for a hint, example somewhere on how could I archieve this using functions.

Thank you in advance, Cheers

Marketingexpert
  • 1,421
  • 4
  • 21
  • 34
  • Are you using `firebase.storage()` on the client-side or `@google-cloud/storage` on the server? If you're limited to 10mb per upload, why not use `Promise.all()` to run multiple uploads at the same time? – adrice727 Dec 19 '17 at 20:19
  • @adrice727 My initial intention is not to use firebase on client side, I want to create a server-less environment and until now I've finished like 80% of my app just by using cloud functions therefore I would use @google-cloud/storage inside my function. How should I proceed? Can you help me – Marketingexpert Dec 19 '17 at 20:40

1 Answers1

4

It would be helpful to see what you have tried so far, but here's simple example of how this might look in a node module. It may be different using cloud functions, but it should at least point you in the right direction:

const Storage = require('@google-cloud/storage');

const storage = Storage({
  projectId: firebaseProjectId,
  credentials: serviceAccountCredentials
});

const bucketName = 'someFirebaseBucket';

const uploadFile = (filename) => {
  return storage
    .bucket(bucketName)
    .upload(filename)
};

const uploadMultipleFiles = (fileList) => {
  const uploads = fileList.map(uploadFile)
  Promise.all(uploads)
    .then(results => {
      // handle results
    })
    .catch(error => {
      // handle error
    })
};
adrice727
  • 1,482
  • 12
  • 17