I have a folder on firebase. which named 'Item'. 'Item' contains 100 images. I just want to fetch just all images Url in the list.
I have tried google documents. Google showing only for a single image. But I just need complete images URLs.
FirebaseStorage firestore = FirebaseStorage.getInstance()
val ref: StorageReference? = firestore.getReference("Item")
I am facing this error =
StorageException has occurred. The object does not exist at the location
As i found in documentation this method could help public Task<ListResult> listAll ()
First you need to get needed reference of the folder in your case it is item/
StorageReference mImageStorage = FirebaseStorage.getInstance().getReference().child("items/");
And then with help of listAll() inflate the list of files in it
Here is the description
https://firebase.google.com/docs/reference/android/com/google/firebase/storage/StorageReference.html#listAll()
You're calling firestore.getReference("Item"), which gives you a StorageReference to that folder. The Android, iOS and JavaScript SDKs of Firebase recently added a method to list the files in a folder to StorageReference.
So you need to loop over the ListResult and call getDownloadUrl to get the download URL for each file. Keep min mind that getDownloadUrl is asynchronous, so it returns a task. Get the actual download URL as shown here: How to get the download url from Firebase Storage?
Related
I am uploading files in the background in Android. And and to cancel it I store the reference. Now when cancel is clicked and I try to get that upload task from the reference it gives 0 results.
Heres my code:
// Storing the reference
StorageReference storeRef = FirebaseStorage.getInstance().getReference().child("Folder1").child("Folder2").child("Filename")
UploadTask task = storeRef.putFile(file);
intent.putExtra("reference", storeRef.toString());
// Retrieving the UploadTask
final String ref = intent.getStringExtra("reference");
if (ref == null) {
return;
}
StorageReference sRef = FirebaseStorage.getInstance().getReferenceFromUrl(ref);
List<UploadTask> taskList = sRef.getActiveUploadTasks(); // taskList.size() ---> 0
You may want to start verifying your database connection and see if the reference is done correctly.
If you can discard that, moving to the next step would be to check the upload method is working, maybe a screenshot or simply checking your database in the console inside Firestore is enough if your files are in the cloud.
As you described, you are uploading files in the background. Following the Handle Activity Lifecycle Changes and using your own implementation would be the best option to correct this behaviour.
If you want to check the full example, it is at the end of the same page. Please be aware this example is for uploading from a stream or data in memory apparently, so you need to add the appropriate “uploading from a file” methods.
Continuing with the downloading of the reference, I would redirect to this page for downloads that continue in the background. In both pages, for uploading and downloading the files, you should add the missing code; this is only compared with the code that you already provided, as many parts are still missing. You should read the guide very carefully to avoid skipping any step. And also check the methods are for the correct data type you are using.
Finally, adding a method for handling errors would be great. As in this case you haven’t found the origin of the issue or got any logs to help us debug your code, this could help you save a lot of time and effort in case you encountered yourself with an issue like this one.
I need to track and update download status(start,pause,play,done) of multiple files in a list that I get from some Api (can't share), onto a RecyclerView.
I am also getting a fileId so each file can be distinguished.
I need download tracking based on the fileId because the Download list is also searchable, it means that the position of items will change and so we can't rely on position based ViewHolder refreshing.
Also if for some reason you close the app, and then go back to the list, search the file, it should show the file download status.
Now there are three options :
a) WorkManager based implementation (how this option can be implemented?)
b) PRDownloader (how this option can be implemented?)
c) Or Android's download manager? (Need to be sure that we need to show progress of multiple files at
same time in a list.)
Which one is better and more reliable?
Which one is the shortest method?
Also can someone share if you have code based on work manager?(how
will you manage to relate fileId to workManger's work id. Do I
need to make a DB table for keeping track of downloads by the Worker?
How to use LiveData from workManager, iff we can in the ViewHolder )
[Reference to Blog/Code/Repos will be most helpful]
Answering my own question(strange!).
I used Fetch Downloader Library
Initialized and used the "Fetch Instance" as a Singleton
Added the download using tag (Maybe I wrongly used the tag. It was supposed to be used for group of downloads. But I used one tag for each download. But it worked.)
Now I did following in the ViewHolder's bind() method :
Took the file Id as a "tag" and removed the FetchObserver linked to
the "tag" i.e. Id using the method of "Fetch Instance" (//will update
the method)
Then again find the download in the "Fetch
Instance" using the Id as "tag".(getDownloadsByTag() method)
If there is a download, you will receive a downloadList whose 0th
element will be your download because I am using one tag per download
and not for group.
Now add the FetchObserver again for that
"tag".
Inside the FetchObserver's lambda, update the progress and other values.
Note : The code can not be shared for non-disclosure purposes. Can share small snippets if you find this confusing.
Im currently working on drawing app and I need to save draw of one of the player in the database
I undrestood that I supposed to use setValue method to save data on specific child:
rooms.child("room " + player.roomNumber).child("draw").setValue(paintView);
"paintView" is my View object.
When running I get this error message:
com.google.firebase.database.DatabaseException: Found conflicting getters for name: isFocusable
The error message is suggesting that you can't use an Android View object as a value in Realtime Database. You can only store data types that are compatible with JSON: string, number, boolean, array, object.
If you're trying to save image data, it's probably not a good idea to use a database at all. Consider instead uploading image data to Cloud Storage instead. You will need to write code to extract the image data from any views you're working with.
I'm working on a prototype app that would read and display data from a large repository of JSON files. I'm currently wondering about the best way to model this behavior in the pubspec.yaml and the in the flutter code itself.
Right now I'm initially loading a catalog file in JSON, this creates a scrollable listview of catalog entries, each of those has its own JSON file in a subdirectory (relative to the catalog file). Do I need to add each new file to the pubspec.yaml, or can I just directly access them.
You could also just access files in the file system without specifying the files in the pubspec.yaml.
Im not sure, if the syntax is still correct, because it is an old project I worked on but it should work in a similar way.
File _themeFile;
Future<Null> _loadThemeFile() async {
String dir = (await PathProvider.getApplicationDocumentsDirectory()).path;
_themeFile = new File('$dir/theme.txt');
if (!await _themeFile.exists()) {
_themeFile.create();
await _themeFile.writeAsString(JSON.encode({
'theme': 'dark',
'colorIndex': 0,
'displayDone': true,
}));
}
}
This snippet looks for the file with the name theme.txt and returns it. If it does not exist, it creates the file. You wouldn't probably need this exactly like that, but I think you can use it as a starting point.
Hello everyone i using this Lazylist , i need this lazy read all image in one path.
example :
i have this path http://www.example.com/image
in this path There are many image
http://www.example.com/image/image1.jpg
http://www.example.com/image/sacimge.jpg
http://www.example.com/image/xxx.jpg
and so on ...
need Lazy read all image in this path and insert in My Listview why How do I do that ???
Unfortunately I don't think this is possible. There is no way for lazyList to know how many images you have and what are their url. I suggest you create webservice
like
http://www.example.com/image/cat
Returning a json or xml array containing all the urls of you images.
On server side you can access your image directory and build this list dynnamicaly.
Then in your app you can call this webservice using (retrofit lib to make it easy for you). Then you can feed this url list into your LazyList.