How to emulate the behavior of "Choose File" file uploading in studio?

Hello! Recently I’ve been messing with Roblox API services and HTTP endpoints in general. I have already figured out problems like authentication and fetching csrf tokens however I’m stuck on the problem of uploading an image the same way the “Choose File” HTML feature does to endpoints. What I tried was to fetch the images from their URL location(to get their binary as a string) and to send that through the HTTP request, also I’ve tried converting the image to b64 encoded information but it didn’t work. I know that I may have to set the content-type to Image/PNG however, I don’t know how to do that when I have to send a dictionary that contains more information than just an image. If anyone is experienced with Roblox endpoints a detailed explanation of sending images through Roblox HTTP endpoints would be very helpful for me and probably other devs on the platform since I couldn’t find any reliable information regarding this issue on online sources, such as this forum.

1 Like

Which exact endpoint are you trying to use?

https://publish.roblox.com/v1/games/{gameId}/thumbnail/image
Basically I want to achieve what the documentation offers(through Choose File) but with using code: https://publish.roblox.com/docs/index.html

1 Like

Okay cool so it seems like you can use a multipart/form-data request body to do it.

The request could be structured something like this:

Headers

You’ll need the usual roblox auth cookies and such. The file upload specific headers you’ll need are below

"Content-Length": <length>
"Content-Type": "multipart/form-data; boundary=---------------------------9372925351920916696323131872"

The boundary signifies where in the body each file content is described as multiple files can be uploaded at once using this type of request. All you need to make sure is to use the same value in the header and at the start of the body.

Body

-----------------------------9372925351920916696323131872
Content-Disposition: form-data; name="Files"; filename="attachment.png"
Content-Type: image/png

<image file binary content>
-----------------------------9372925351920916696323131872--

There may be other ways to send the data too but this is how it works if you check the network tab of your browser when you make the request using that api page.