Przejdź do głównej zawartości

initiateFileUpload

Dla: Programista

MutacjaBetaMutation.initiateFileUpload

Starts uploading a file to an order or a product: records the file as pending and returns a signed URL to send its content to. Then send the content in one request and call completeFileUpload. An upload not completed within an hour may be dropped (its file becomes FAILED).

Wymagany zakresfiles:write
Dostępne odPrynt 0.28.0
StabilnośćBeta (co to znaczy)
PonawianieWysyłaj nagłówek Idempotency-Key, żeby ponowienie nie wykonało zapisu drugi raz. Zapisy i idempotencja

Argumenty

NazwaTypOpis
inputwymaganeInitiateUploadInput!

The file to upload and the record to attach it to.

Zwraca

InitiateUploadResult!

Przykład

Mutacja
mutation StartUpload($input: InitiateUploadInput!) {
initiateFileUpload(input: $input) {
fileId
uploadUrl
method
expiresAt
requiredHeaders
}
}
Zmienne
{
"input": {
"filename": "ulotka-a5.pdf",
"mimeType": "application/pdf",
"sizeBytes": 2457600,
"entityType": "PRODUCT",
"entityId": "c06a8203-5e7f-4192-8dbe-3f4a5b6c7d85"
}
}
Wywołanie (curl)
IDEMPOTENCY_KEY=$(uuidgen) # ponawiaj z tym samym kluczem
curl -sS https://twoja-drukarnia.prynt.pl/api/v1/graphql \
-H "Authorization: Bearer $PRYNT_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
--data-binary @- <<'JSON'
{
"query": "mutation StartUpload($input: InitiateUploadInput!) {\n initiateFileUpload(input: $input) {\n fileId\n uploadUrl\n method\n expiresAt\n requiredHeaders\n }\n}",
"variables": {
"input": {
"filename": "ulotka-a5.pdf",
"mimeType": "application/pdf",
"sizeBytes": 2457600,
"entityType": "PRODUCT",
"entityId": "c06a8203-5e7f-4192-8dbe-3f4a5b6c7d85"
}
}
}
JSON
Odpowiedź
{
"data": {
"initiateFileUpload": {
"fileId": "e18da4c5-7092-4db4-8fd0-5b6c7d8e9fa7",
"uploadUrl": "https://storage.example.com/pliki/ulotka-a5.pdf?signature=…",
"method": "PUT",
"expiresAt": "2026-10-05T10:41:02.000Z",
"requiredHeaders": "{\"Content-Type\":\"application/pdf\",\"Content-Length\":\"2457600\"}"
}
}
}