ComputerCraft Forums

ComputerCraft => Ask a Pro => Topic started by: Random_TNT on Jul 05, 2022, 06:18 PM

Title: Send files over http
Post by: Random_TNT on Jul 05, 2022, 06:18 PM
Hey, i wanted to make an app store for my os, i need to know how to send files to my app store server
Title: Send files over http
Post by: Erb3 on Jul 06, 2022, 06:29 PM
Hey, Welcome to the forums!

To send a file with the http api, you can use something like the following code:
local data = fs.open("fileToSend.lua", "r").readAll()
http.post("http://example.com/appstore/submit_app", "file=" .. data)

I replaced the example URL with a web server, and the result is:
(https://camo.tmpim.com/4a7cfef40da771326e0685c8ddecfdcb4d0fa1bd/68747470733a2f2f692e696d6775722e636f6d2f643956445178702e706e67)
This is the body of the HTTP request.

The first line opens the file in read mode, and reads its contents.
The next line sends a POST request to the URL with the filecontents in the body.

Good luck with your OS, reply with a comment if my code dosent work, or if it works feel free to let me know too 😉.