简体   繁体   中英

Save multiple files to Firebase storage using cloud functions

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

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
    })
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM