Lorc520

testing

May 20th, 2025 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. -- local filePath = "testsound.mp3"
  2. local url = "https://remote.craftos-pc.cc/music/upload"
  3.  
  4. -- mp3 name request
  5. print("Please enter the name of your mp3")
  6. local filePath = read()
  7. if not filePath:lower():match("%.mp3$") then
  8. filePath = filePath .. ".mp3"
  9. end
  10.  
  11.  
  12. -- Open the file in binary mode
  13. local file = fs.open(filePath, "rb")
  14. if not file then
  15. print("Failed to open file: " .. filePath)
  16. return
  17. end
  18.  
  19. local fileData = file.readAll()
  20. file.close()
  21.  
  22. -- Perform HTTP POST request
  23. local response = http.post(url, fileData, {
  24. ["Content-Type"] = "application/octet-stream",
  25. ["Content-Length"] = tostring(#fileData)
  26. })
  27.  
  28. -- Handle response
  29. if response then
  30. local result = response.readAll()
  31. response.close()
  32. else
  33. print("Upload failed.")
  34. end
  35.  
  36. print(result)
Advertisement
Add Comment
Please, Sign In to add comment