Upload media
Uploading takes three calls: create the asset, send the bytes straight to
storage, then complete it. Needs media:upload.
-
Start (
startMediaUpload):- bash / zsh
- fish
- PowerShell
curl -X POST "$GHOSTPULL_URL/api/v1/media/assets" \-H "x-api-key: $GHOSTPULL_API_KEY" -H "Content-Type: application/json" \-d '{"name":"shoe.png","mediaType":"image/png","sizeBytes":48213}'curl -X POST "$GHOSTPULL_URL/api/v1/media/assets" \-H "x-api-key: $GHOSTPULL_API_KEY" -H "Content-Type: application/json" \-d '{"name":"shoe.png","mediaType":"image/png","sizeBytes":48213}'curl.exe -X POST "$env:GHOSTPULL_URL/api/v1/media/assets" `-H "x-api-key: $env:GHOSTPULL_API_KEY" -H "Content-Type: application/json" `-d '{"name":"shoe.png","mediaType":"image/png","sizeBytes":48213}'The answer has
assetId,versionIdanduploadwith aurlandheaders. The URL works once, for an hour. -
Send the bytes with
PUTtoupload.url, with every header fromupload.headers, and no API key: the URL itself is the permission.- bash / zsh
- fish
- PowerShell
curl -X PUT "$UPLOAD_URL" -H "Content-Type: image/png" -H "If-None-Match: *" \--data-binary @shoe.pngcurl -X PUT "$UPLOAD_URL" -H "Content-Type: image/png" -H "If-None-Match: *" \--data-binary @shoe.pngcurl.exe -X PUT "$env:UPLOAD_URL" -H "Content-Type: image/png" -H "If-None-Match: *" `--data-binary "@shoe.png"Sending again after a success is refused by storage: the version's file can be written only once (
If-None-Match: *). Without that header, storage refuses the upload with403. -
Complete (
completeMediaUpload):- bash / zsh
- fish
- PowerShell
curl -X POST "$GHOSTPULL_URL/api/v1/media/versions/$VERSION_ID/complete" \-H "x-api-key: $GHOSTPULL_API_KEY"curl -X POST "$GHOSTPULL_URL/api/v1/media/versions/$VERSION_ID/complete" \-H "x-api-key: $GHOSTPULL_API_KEY"curl.exe -X POST "$env:GHOSTPULL_URL/api/v1/media/versions/$env:VERSION_ID/complete" `-H "x-api-key: $env:GHOSTPULL_API_KEY"The answer is the asset, now in your library. A
409means the bytes are not there yet, or the upload was completed before; read the asset withgetMediaAssetto see which.
Read your library
listMediaAssets and getMediaAsset (media:read) answer assets with a
signed url for each file. These links expire: read the asset again for a
fresh one instead of storing links.