Take a file input via URL?


I’ve been using the Gradio Spaces’ API functionality for a number of features in my app. I have a new space that takes an uploaded file as an input. The API documentation for this space expects the following in the request body:

  "data": [
 : { name: string; data: string }, // represents file name and base64 data as an object of 'file' File component

I don’t understand how I should send this file input. As an alternative to this, I was wondering if it would be possible to send the S3 location of my file, its url, as an input instead of whatever I’ve pasted above. Does anyone know if this is possible and has anyone done something like this?

Thank you for any help/guidance you can provide!

Solved - I was able to use a Base64 encoding API to send the file in the format the Gradio Space was expecting.

1 Like

Hi @vamsi-tetali, can you please share the details for this solution? Like, what API did you use and if you could provide a code snippet it would be a great help. I am stuck.

I was sending my file from a Bubble.io app. Within the Bubble ecosystem, there is a plugin that can be used to encode a file into base64 and then send it to my huggingface space that requires a file input. In addition to the base64 encoded version of the file, my space also needs filename to be sent as a parameter. For that I simply sent the file’s name as a string.

Base64 encoding is a very common thing in many APIs (especially those related to email). If you are curious about what it means to encode your file as a base64 string, follow this link, upload your file, select “Data URI” as the “Output Format” and see the base64 encoded version of your file: File to Base64 | Base64 Encode | Base64 Converter | Base64

This base64 encoded version of your file is what huggingface expects when you have a space that needs files as an input.

1 Like

Okay. Thanks.