Sending a File Through an HTTP POST Request

I’ve searched the forum to try and find a method but I haven’t found anything. Basically, I’m trying to send a simulation of a file to the Trello API in order to attach it to a card.

URL: https://api.trello.com/1/cards/{id}/attachments
Documentation: https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-post

I’ve tried to send it through the request’s body and changing the Content-Type header, but that didn’t work.

Are there any ways of directly sending a file or simulating a file in a POST request (in the binary format)?

What are you attaching? If you are attaching a roblox image, you just use roblox content service url to get it. Here is the url: https://www.roblox.com/Thumbs/Asset.ashx?width=420&height=420&assetId=" .. assetID

I’d be attaching a text file (.txt).

I’m pretty sure you can just send a string.

1 Like

Why are you trying to send a file through Roblox? You can’t do that unless you make the up the binary data for it, as stated by the documentation:
image

Roblox does not allow for uploading of files, so either update the description of your card to include the said text or guide it through a proxy. If you are really dedicated, create the appropriate binary representation of said file and send it over using the file argument.

If you aren’t doing this via Roblox, then this isn’t the forum to post it with. If you are using an external service and have no connections to the Roblox platform, then utilize StackOverflow instead.

Lastly, I personally do not see why you’d attach it as a file, but you know what’s best. To do it purely via Roblox, you need to convert the string to binary data that represents a txt file with the string contents. If not, then you could utilize a proxy that uploads the file based on what is received. That seems like an easier solution to me.

If you want to convert it to binary, then you can try utilizing pre-made Base64 Lua libraries in order to encode the string and from there do some research on the Base64 representation of a txt file. A base64 lua converter that I was able to find was iskolbin/lbase64. See if you can get away with sending just the converted text, otherwise you’ll need to figure out a way to “convert” it into a txt file.

1 Like

As far as I can tell, this isn’t necessary. It appears files are just loaded as plain text on a string, so a .txt file will just have the actual, readable text that’s written inside it, and using :GetAsync gets that text. I’m not sure if it’s different for :PostAsync, but I think it’s a reasonable assumption that a file is just represented as a string of it’s contents.

1 Like

I do not believe so. The documentation specifies binary data, along with some extra parameters to specify the file name and file type. This was also visible on other posts asking for help on the API. All of them converted to binary data. Additionally, this is an API that can be used to upload literally any type of file, so having a string passed as a parameter seems odd, especially when considering that the expected parameter is binary data. I do strongly believe that conversion is needed as it would make the most sense.

Alright, I should have experimented with this specific endpoint a little bit more. Turns out that the file value can straight up be the contents.