Uploads
Create an upload URL
Get a signed, single-use URL to PUT a PDF, DOCX or PNG file to, up to your account's maximum document size, then use the upload in an envelope.
Upload a file from your server in two requests: describe the file to get a signed upload URL, then PUT the file’s bytes to that URL. The result is a temporary upload that you use as a document’s url.
Use this for files larger than 4.5 MB, up to your account’s maximum document size (10 MB by default). For smaller files, Create an upload is simpler: one call, at most 4.5 MB per request. Any API key works, test or live: uploads belong to your account, not to a mode.
How it works
- The API checks
media_typeandsizeagainst your account’s limits when you request the upload URL, before you send any bytes. - Requesting an upload URL creates nothing: the PUT creates the upload. An upload URL you don’t use expires after five minutes.
- The PUT must carry the
sizeand SHA-256 you declared. Bytes that don’t match are refused.
How to upload a file
Request an upload URL
Read the file and compute its size in bytes and the SHA-256 of its bytes, as 64 lowercase hexadecimal characters. Send them with the file’s media_type to POST /v1/upload-urls.
The response has an upload_url to send the bytes to, the reference the upload will have, and expires_in, the seconds left to use upload_url (300).
PUT the bytes
Send a PUT request to upload_url before it expires. The body is the raw file bytes, exactly the ones you described, not a multipart form. Set these headers:
| Header | Value |
|---|---|
Content-Type | The media_type you sent |
Content-Length | The size you sent (most HTTP clients set it for you) |
x-amz-content-sha256 | The sha256 you sent |
The PUT needs no API key: the signed URL carries the authorization. A 2xx response means the file is stored and the upload exists. If the PUT fails, request a new upload URL and try again.
Use the upload in an envelope
Pass reference as the url of a document when you create an envelope:
{
"url": "https://api.signatureapi.com/v1/uploads/upl_3JJz6t1o8A5YjX5VpnX27Z",
"format": "pdf"
}FILE=contract.pdf
SIZE=$(wc -c < "$FILE" | tr -d ' ')
SHA256=$(shasum -a 256 "$FILE" | cut -d ' ' -f 1)
RESPONSE=$(curl -s -X POST https://api.signatureapi.com/v1/upload-urls \
-H "X-API-Key: $SIGNATUREAPI_KEY" \
-H "Content-Type: application/json" \
-d "{\"media_type\": \"application/pdf\", \"size\": $SIZE, \"sha256\": \"$SHA256\"}")
curl -X PUT "$(echo "$RESPONSE" | jq -r .upload_url)" \
-H "Content-Type: application/pdf" \
-H "x-amz-content-sha256: $SHA256" \
--data-binary "@$FILE"
echo "$RESPONSE" | jq -r .referenceimport { createHash } from "node:crypto";
import { readFile } from "node:fs/promises";
const bytes = await readFile("contract.pdf");
const sha256 = createHash("sha256").update(bytes).digest("hex");
const response = await fetch("https://api.signatureapi.com/v1/upload-urls", {
method: "POST",
headers: {
"X-API-Key": process.env.SIGNATUREAPI_KEY!,
"Content-Type": "application/json",
},
body: JSON.stringify({ media_type: "application/pdf", size: bytes.length, sha256 }),
});
const { upload_url, reference } = await response.json();
const put = await fetch(upload_url, {
method: "PUT",
headers: { "Content-Type": "application/pdf", "x-amz-content-sha256": sha256 },
body: bytes,
});
if (!put.ok) throw new Error(`Upload failed: ${put.status} ${await put.text()}`);
console.log(reference); // the document urlimport hashlib
import os
import requests
with open("contract.pdf", "rb") as f:
data = f.read()
sha256 = hashlib.sha256(data).hexdigest()
response = requests.post(
"https://api.signatureapi.com/v1/upload-urls",
headers={"X-API-Key": os.environ["SIGNATUREAPI_KEY"]},
json={"media_type": "application/pdf", "size": len(data), "sha256": sha256},
)
upload = response.json()
put = requests.put(
upload["upload_url"],
headers={"Content-Type": "application/pdf", "x-amz-content-sha256": sha256},
data=data,
)
put.raise_for_status()
print(upload["reference"]) # the document urlBody Parameters
The media type of the file.
application/pdfapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentimage/png
Example "application/pdf"
The size of the file in bytes, up to the account's maximum document size.
minimum 1Example 102400
The SHA-256 hash of the file bytes, as 64 lowercase hexadecimal characters.
pattern ^[a-f0-9]{64}$Example "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
Returns
Returns a 200 OK status code and the upload URL on success, or an error otherwise. A size over your account’s maximum document size returns a validation-error.
The signed, single-use URL to PUT the file bytes to, with content-type, content-length and x-amz-content-sha256 (the declared SHA-256), before it expires.
format uriExample "https://uploads.signatureapi.com/v1/uploads/upl_1sAAaVfabdt0esVjmSTmLA?token=example-signed-token"
The upload's URL. It can be used as a document url once the PUT lands.
format uriExample "https://api.signatureapi.com/v1/uploads/upl_3joO7lxE8HVhOZmkCHFCxK"
The number of seconds until upload_url expires.
minimum 1Example 300
Once the PUT succeeds, reference works anywhere a document URL is accepted, and Retrieve an upload returns it. The upload is temporary and is deleted 24 hours after the PUT. To keep it for reuse across envelopes, store the upload with the upload ID, the last path segment of reference.
Errors on the PUT
The PUT is refused, and nothing is stored, when:
Content-Type,Content-Lengthorx-amz-content-sha256is missing (400).Content-Typeorx-amz-content-sha256differs from what you declared, or the body is larger than the declaredsize(422, upload-claim-mismatch).upload_urlhas expired (422, expired-upload-token).upload_urlwas changed after the API returned it (422, invalid-upload-token).- The upload id already exists with different claims (
409, upload-idempotency-conflict).
The body itself is also checked: bytes whose SHA-256 differs from x-amz-content-sha256 are refused with a 400.
Request a new upload URL for each new attempt.
POST /v1/upload-urls HTTP/1.1
Host: api.signatureapi.com
X-API-Key: YOUR_API_KEY
Content-Type: application/json
{
"media_type": "application/pdf",
"size": 102400,
"sha256": "4f1c8a7e92b3d05a6e8c1f4b7d2a9053c6e8b1d4f7a20935c8e1b4d7a0f36c92"
}{
"upload_url": "https://uploads.signatureapi.com/v1/uploads/upl_3JJz6t1o8A5YjX5VpnX27Z?token=example-signed-token",
"reference": "https://api.signatureapi.com/v1/uploads/upl_3JJz6t1o8A5YjX5VpnX27Z",
"expires_in": 300
}{
"type": "https://signatureapi.com/docs/v1/errors/validation-error",
"title": "Validation Error",
"status": 422,
"errors": [
"size must be a maximum of 10 MB."
]
}Errors every call can return are in Errors and Authentication.