File resource duplicates object

Options

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

  • Leo Med
    Leo Med Member
    Options

    Please help me out🙏, this is seriously blocking me 😣

  • Guillaume Maison
    Guillaume Maison Member ✭✭
    Options

    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.

  • Leo Med
    Leo Med Member
    Options

    I'm just sending one file at once along with some data

  • Guillaume Maison
    Guillaume Maison Member ✭✭
    Options

    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.

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    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.

  • Leo Med
    Leo Med Member
    Options

    The function stack, looping the create_variation function with variations array

    The create_variation function and how I proceed the file resource

  • Guillaume Maison
    Guillaume Maison Member ✭✭
    Options

    @Leo Med
    Have you tried to create an API endpoint where you would just send 1 variation ? (ie just 1 file) …

  • Leo Med
    Leo Med Member
    Options

    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

  • Guillaume Maison
    Guillaume Maison Member ✭✭
    Options

    @Leo Med and it works ?

  • Leo Med
    Leo Med Member
    Options

    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

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    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.

  • Leo Med
    Leo Med Member
    Options
  • Guillaume Maison
    Guillaume Maison Member ✭✭
    Options

    at which point does the array duplicate and stores the file resource in another row ?

  • Leo Med
    Leo Med Member
    Options

    @Guillaume Maison

    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

  • Guillaume Maison
    Guillaume Maison Member ✭✭
    Options

    @Leo Med can you trace the HTTP request sent to the endpoint ?
    just to check it's not coming from calling side…

  • Guillaume Maison
    Guillaume Maison Member ✭✭
    edited June 2023
    Options

    And also can you show in the Request history of your Endpoint how are set the inputs ?

  • Leo Med
    Leo Med Member
    edited June 2023
    Options

    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 👆️

  • Guillaume Maison
    Guillaume Maison Member ✭✭
    Options

    @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 ?

  • Leo Med
    Leo Med Member
    Options

    @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).

  • Leo Med
    Leo Med Member
    Options

    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 .

  • Leo Med
    Leo Med Member
    Options

    Hey @Chris Coleman, any news about this ? I would still prefer to achieve this the normal way

  • Leo Med
    Leo Med Member
    Options

    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!

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    @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.