File resource duplicates object
Hey everyone, hope you're doing well. I have an issue apparently caused by a file resource. I have this input that is a list of objects
The data I send from the frontend is this
I then do a loop on the variations list to perform the desired action, but I'm being confronted with the loop running twice even I just sent one object. I printed out the data to see what are those two objects and this is the result
It seems like the other object is created to contain the file resource, I don't really understand why. I tried to send the variations object without the file resource and everything worked fine. Please help me with this! Thanks!
Answers
-
Please help me outπ, this is seriously blocking me π£
-
i can't find where i've read it, but if i remember well, you can't send several files at once.
you have to make a loop to send each item + file of your array from the front side.
But i can be mistaken. -
I'm just sending one file at once along with some data
-
According to your screenshot, your sending several files at once : an array of items with each containing a file.
in fact, you have to call your endpoint not with an array of files, but one file at a time. -
Can you show us your function stack? It's possible there's just an issue with how you're targeting the image or something else that's happening in the loop itself.
-
The function stack, looping the create_variation function with variations array
The create_variation function and how I proceed the file resource
-
@Leo Med
Have you tried to create an API endpoint where you would just send 1 variation ? (ie just 1 file) β¦ -
Yes, I have an endpoint to create a variation (ie 1 file sent) and everything is working perfectly. By the way, I just converted that endpoint to a function and it is the one I'm now calling in the loop to create multiple variations
-
@Leo Med and it works ?
-
Creating a variation with only one file sent worked perfectly.
I also have another enpoint that manage a list of file resources and it is also working perfectly, so I'm not sure it is about sending several files because it all depends on how you manage the received list
-
I'm curious about the inputs mapped when you call the custom function β can you show that to me as well? My guess right now is you are targeting the variations input directly instead of the item variable; just want to be sure.
-
-
at which point does the array duplicate and stores the file resource in another row ?
-
In the example ποΈ of data I'm sending from the frontend. We are okay I'm sending variations as this
but serialized to be sent as a formData (the serialized format works well, used on other endpoints ).
So there is just one object in the variations array. I printed out the variations array before the loop and here is the result
-
@Leo Med can you trace the HTTP request sent to the endpoint ?
just to check it's not coming from calling side⦠-
And also can you show in the Request history of your Endpoint how are set the inputs ?
-
I forgot to notice in the request history, this is how variations looks like(doesn't show 2 objects like from the function stack print). It only shows product_image attribut but in case I don't send an image, it shows the rest of the data
@Guillaume Maison , the request url is like this: https://xxxx.xano.io/api:xxx/product?company_id=2, and the details ποΈ
-
@Leo Med
Could you try this :
when building your payload, could you produce 2 arrays :
1. the variations data (ie vdatas)
2. the variations file (ie vfiles)
you should have vfiles[0] "="vdatas[0]
and modifying accordingly your endpoint's inputsβ¦
And check again ? -
@Guillaume Maison It worked perfectly that way, thank you for the workaroundποΈ, I can now move on.
It seems to be a bug, I hope it will be fixed soon (if confirmed as a bug of course).
-
For anyone else facing this issue, this is clearly what I did
1- Split my variations data into 2 differents arrays, one for simple data(variations ποΈ) and the other only for files (files ποΈ). You must ensure that both arrays are same length and the indexes match well.
2- Make a For loop (not a ForEach) on one of the arrays length and then get variation and file at the current index (var:array|get(index)) to proceed the desired function
Thanks to @Guillaume Maison .
-
Hey @Chris Coleman, any news about this ? I would still prefer to achieve this the normal way
-
Can you tell me if this is a bug and I should expect a fix or if I've done something wrong? The workaround is just a workaround and has its own nightmares. I'd really prefer the more obvious way of doing this (the one I was trying). Not cool to leave me unanswered on this @Chris Coleman
@Michael Udinski, @Lachlan π
The feature I'm implementing is still on pending because of this!
-
@Leo Med Please reach out to us via support chat about this; I'm not able to reproduce this behavior in my own recreations and expect there is something going on with the input.
Categories
- All Categories
- 46 π£ Announcements
- 47 π¦Ύ Releases
- 36 π Welcome
- 924 π€· Help! I'm a Noob
- 113 π± No-Code Front-Ends
- 597 π Working with APIs
- 418 π’ Transforming data
- 120 π Connect Xano to ...
- 46 π§βπ» Find an Expert
- 320 βOther questions
- 32 π Security
- 22 βοΈ Snippets
- 19 π Showcase
- 7 π£οΈ ο»Ώ Xano Chatter
- 60 πΊ Video Tutorials
- 166 π Request a feature
- 219 π Report a Bug
- 19 π Templates & Extensions
- 6 π¬ Feedback