0

I am trying to create an instagram style app on flutter, the only difference the feed is curated and not generated by user uploaded images. I have uploaded all the files I want to show to the user on Cloud Storage. I tried two different methods to display the feed and both failed.

Method 1 Using Google Cloud Function I was trying to emulate this. Basically, I was trying to use the cloud function to generate links of my files and then feed them into documents in Fire Store, I would have then queried the firestore. I deployed the google cloud storage function, tried using getSignedUrl but was pretty much stuck after it.I am not even sure how to get the URLs much less make a document for each of them

const functions = require('firebase-functions');


var admin = require("firebase-admin");

var serviceAccount =require("myname.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "myname.com"
});

/* const myFile = admin.storage().bucket().file('path/to/my/file');
myFile.getSignedUrl({action: 'read', expires: someDateObj}).then(urls => {
    const signedUrl = urls[0]
}); */


function getSignedUrl() {
    const gcs = require('@google-cloud/storage')({keyFilename: 'myname.json'});
// ...
const bucket = gcs.bucket(bucket);
const file = bucket.file(fileName);
return file.getSignedUrl({
  action: 'read',
  expires: '03-09-2491'
}).then(signedUrls => {
  // signedUrls[0] contains the file's public URL
});
    
}

Method 2 Using for loop in flutter I tried to do what this guy did I made a text files that contains the names of all the files and then appended them to a link. Using a for loop I was able to generate a rudimentary feed but it repeats images and doesn't display more than 10 images.

while(i != numOfImages && i != imageNames.length) {
      String filePath = imageFolderPath + imageNames[i];
      // imageNames.shuffle();

      imageUrls.add(await getDownloadUrl(filePath));
      i++;
    }

    return imageUrls;
  }

Can someone please help me with method 1?

1 Answers1

0

okay so basically in firebase storage you can upload images (which is from what I understood is what you did in the first method) now if the application has access to firebase storage then you could use the URL of the image and the network image widget to load an image. To create a feed get the list of image URLs and use ListView.builder to generate a list of network images and use the URLs that you loaded. You could also use cached network image for a better feel and frontend performance.

edit:

this is how you can get the imageURL solution

Nayef Radwi
  • 1,305
  • 13
  • 25