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?