Is there a way to get the each object data in the storage.listObjects() ?

Is there a way to get the each object data in the storage.listObjects() ?

iklimis
Advocate Advocate
481 Views
5 Replies
Message 1 of 6

Is there a way to get the each object data in the storage.listObjects() ?

iklimis
Advocate
Advocate

Hello!
I currently use the listObjects() method with a prefix to get a list of objects that I previously saved. This method will return an array with the key of the object along some metadata. So, if my list has 10 objects I have to subsequently make 10 calls to the storage.getTextObject() with the keys to get a list of my objects. 

Is there a way so I just make the one to get all the objects along with their data based on a prefix??

Or alternatively is there some other approach you can recommend?  

Thank you

0 Likes
482 Views
5 Replies
Replies (5)
Message 2 of 6

vilde.barth
Autodesk
Autodesk

Hi,

 

You are right in that you have to do one call per object you want to get. However, these calls can be run in parallel using e.g. Promise.all([promise1, promise2,..]). Hope this answers your question.

 

Vilde

0 Likes
Message 3 of 6

iklimis
Advocate
Advocate

@vilde.barth Thanks for your reply!

Yes I imagined as much - in that I will have to chain a number of Promises - but isn't  somewhat risky say if I have to make 10 calls subsequently ? 
What if one or more fail? Either I have to catch the whole error and make the user retry or I have to keep track of the failed ones and again restart the chain for the failed Promises.


that might nor be optimal for UX

 

0 Likes
Message 4 of 6

vilde.barth
Autodesk
Autodesk

@iklimis I see your concern, but I do not believe this is something we will support. Can you explain your use case for needing to make 10 calls so we can better understand your concern? 🙂 

 

Also, if you want to keep track of the each of the promises, you can use Promise.allSettled(..). 

 

0 Likes
Message 5 of 6

iklimis
Advocate
Advocate

@vilde.barth Hi!
Yes let me try to explain the use case: I would like to keep an item list of sorts. Each list item has its own metadata. Think of it as a Todo app. 

In my welcome page I would like to show all todos which some todo info. I would like to take all todos from the storage with one call instead of keeping a list of todo-ids and getting each todo info by making a seperate storage call for each todo.
I would like to avoid say in a case of 20 Todos to make 20 storage calls for each individual Todo info.

0 Likes
Message 6 of 6

vilde.barth
Autodesk
Autodesk

@iklimis Thanks for explaining! I understand your use case, but I do not believe we will add support for getting multiple objects at the same time. If I understand correctly and you want to access all of the items at the same time, is it an alternative for you to store all the data in one object?

0 Likes