-
Goal:
Hi, I would like to create a resource that uploads an image file to an endpoint. The endpoint expects a key calledattachment_upload
as a key and I would like to upload the file given infileInput2.value
. -
Steps:
I have tried putting inname
anddata
into a javascript object as the value.
I have formatted correct key-value pair calledattachment_upload
as given in the screenshot.
I am able to verify that no other modifications to the request are needed given that it works in postman without other changes to the request:
-
Details:
The error message:
-
Screenshots:
Hi @Ali_Reza_Mosavi,
Welcome to Retool - the fileInput component stores data as an array, so you might need to set the value to {{ fileInput1.value[0] }}
to get the first element. You can right click on the component, select "view state" and then you can explore all the properties of the component - very helpful for debugging this kind of issue. You'll see the array object has properties for the base64data, filename, size and type.
Hi @MikeCB .
Thank you. This did not work for me. The same error appears again. It also appears that the retool documentation says that .value
should give the correct schema when making a Form-Data
PUT request. See this link under the form data section:
However, when using Postman, no other special modifications to the request are needed other than the selected file along with Form-Data
specified as the request body.
Does your input tell you what format the "file" object you are sending is supposed to be?
The Retool file input object is:
{
name: string;
type: string;
sizeBytes: number;
base64Data: string;
}
If your API is expecting something different/more/less in terms of key names, you may need to transform it before you send.
It appears my data is being interpreted as a string object when I hover over it when I want it as a binary.
Here's how my request looks like, I can confirm that it expects binary because using this script in python works and reads it in binary:
When the request is sent over, this should technically be binary, correct?
Hi @Ali_Reza_Mosavi,
I wanted to flag this post in case it's helpful! I'm not sure if you need this level of customization, but I thought I'd send it over just in case.
It might help to see the Postman request as a code snippet so that we have a more direct comparison to Retool: