How to get a list of all files in Cloud Storage in a Firebase app?

后端 未结 19 1029
傲寒
傲寒 2020-11-21 11:25

I\'m working on uploading images, everything works great, but I have 100 pictures and I would like to show all of them in my View, as I get the complete list of

19条回答
  •  花落未央
    2020-11-21 11:51

    One more way to add the image to Database using Cloud Function to track every uploaded image and store it in Database.

    exports.fileUploaded = functions.storage.object().onChange(event => {
    
        const object = event.data; // the object that was just uploaded
        const contentType = event.data.contentType; // This is the image Mimme type\
    
        // Exit if this is triggered on a file that is not an image.
        if (!contentType.startsWith('image/')) {
            console.log('This is not an image.');
            return null;
        }
    
        // Get the Signed URLs for the thumbnail and original image.
        const config = {
            action: 'read',
            expires: '03-01-2500'
        };
    
        const bucket = gcs.bucket(event.data.bucket);
        const filePath = event.data.name;
        const file = bucket.file(filePath);
    
        file.getSignedUrl(config, function(err, fileURL) {
            console.log(fileURL);
            admin.database().ref('images').push({
                src: fileURL
            });
        });
    });
    

    Full code here: https://gist.github.com/bossly/fb03686f2cb1699c2717a0359880cf84

提交回复
热议问题