In my app, users can select local files and upload them to GCS using a resource query.
I'm trying to add an option to upload instead of from the local filesystem from the cloud. I have an API call that returns the url of the generated image.
I can't figure out a way to pass the url or binary to the resource query.
Looks like I can't set a File object in a variable. I also read that I can't set the file of an input file component. I also can't have async transformations (url -> file). I can't define additional scope variables from my resource query.
Any ideas how this could be done? Thanks! ![:pray: :pray:](https://community.retool.com/images/emoji/apple/pray.png?v=12)
Hey @Christian_G, if you have the url of the file, then in general you can use a GET REST API query to retrieve the binary of the file to pass to the upload query.
Step 1 of this reply here should show you how to get it.
Let me know if that doesn't work for you.
Hi Joe, downloading the URL to a file is easy, the problem is the upload. How can I pass it to the query without using the client file selector? Can I upload it to GCS as base64 string? ![:thinking: :thinking:](https://community.retool.com/images/emoji/apple/thinking.png?v=12)
@Christian_G They type of upload / content type can be set depending on the data you are trying to upload. If you want, you can supply the file object returned from the REST API query to the GCS upload query.
GET REST API:
GCS Upload:
You'll notice that the file object returned by the REST API query is the same as a file object from a file uploaded using the client file selector.
REST data:
![CleanShot 2024-06-25 at 13.16.48@2x](https://community.retool.com/uploads/default/original/3X/8/7/8762ce0333804d1a2669abe75194d9c033b8aa7f.png)
File Selector:
![CleanShot 2024-06-25 at 13.16.31@2x](https://community.retool.com/uploads/default/original/3X/c/f/cf724a1eda9b7f3c78406b4d1cfa097bbb41bb05.png)
Let me know if you have any other questions.
If you want to change any of the file object information, you can do so by creating an intermediate JS query just like in the other post.
In my case, I have a button that fetches the image and sets a temporary variable. Thanks to you I could set such variable to emulate the file selector interface. Then I reuse the same upload query which checks if to use the temporary one or the selected file. But the image uploaded is corrupted and it is always 15 Bytes.
GCS upload:
Download script:
Any idea what could be wrong?
Thanks! ![:pray: :pray:](https://community.retool.com/images/emoji/apple/pray.png?v=12)
The 15Bytes file seems to be a txt file containing "[object Object]" ![:smiley: :smiley:](https://community.retool.com/images/emoji/apple/smiley.png?v=12)