update doc
This commit is contained in:
56
etc.jl
Normal file
56
etc.jl
Normal file
@@ -0,0 +1,56 @@
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user