57 lines
1.6 KiB
Julia
57 lines
1.6 KiB
Julia
using HTTP, Arrow, JSON, DataFrames
|
|
|
|
df = DataFrame(id = 1:10_000, val = rand(10_000))
|
|
|
|
file_server_url = "http://192.168.88.104:8080"
|
|
url_getUploadID = "$file_server_url/api/upload"
|
|
|
|
function upload_to_plik(url, df)
|
|
# 1. Build the Request object manually
|
|
headers = [
|
|
"X-Plik-TTL" => "5m",
|
|
"Content-Type" => "application/octet-stream",
|
|
"Transfer-Encoding" => "chunked"
|
|
]
|
|
|
|
# We create a request with an empty body, but we'll stream into it
|
|
req = HTTP.Request("POST", url, headers)
|
|
|
|
# 2. Open the connection manually to get a raw Stream
|
|
local_url = ""
|
|
HTTP.open("POST", url, headers) do stream
|
|
# WRITE PHASE
|
|
# Arrow.write handles the 'chunked' encoding automatically
|
|
Arrow.write(stream, df; file=false)
|
|
|
|
# CLOSE WRITE / START READ
|
|
# This is the critical hand-off.
|
|
# We tell the kernel we are done sending.
|
|
HTTP.closewrite(stream)
|
|
|
|
# Now we wait for the server's response
|
|
resp = HTTP.startread(stream)
|
|
|
|
# Handle the body
|
|
if resp.status == 200 || resp.status == 201
|
|
payload = read(stream, String)
|
|
# Depending on Plik version, it might return the URL directly
|
|
# or a JSON object. Adjust accordingly:
|
|
try
|
|
local_url = JSON.parse(payload)["url"]
|
|
catch
|
|
local_url = payload # Fallback if it's a raw string
|
|
end
|
|
else
|
|
error("Plik rejected upload with status: $(resp.status)")
|
|
end
|
|
end
|
|
|
|
return local_url
|
|
end
|
|
|
|
url = upload_to_plik(url_getUploadID, df)
|
|
|
|
|
|
|
|
|