Generate upload URL
Generate a file browser upload URL with authentication credentials for uploading files directly to a website's file storage.
Generate a file browser upload URL with authentication credentials for uploading files directly to a website's file storage.
Returns url, auth_key and rest_auth_key. Use these to upload a file to the
website's public_html directory via the TUS resumable upload protocol (TUS 1.0.0).
Send X-Auth: {auth_key} and X-Auth-Rest: {rest_auth_key} headers on every request
below.
- Create the upload:
POSTto{url}/{relative_file_path}?override=truewith headersupload-length: {file size in bytes}andupload-offset: 0. Expect201 Created. - Upload the file: send the file bytes to the same location (any TUS 1.0.0 client, or
PATCHrequests with anupload-offsetheader tracking progress) until complete.
relative_file_path is the destination path inside public_html, e.g. app.zip.
Instead of a TUS client, plain curl also works:
FILE=app.zip
SIZE=$(stat -f%z "$FILE") # stat -c%s on Linux
curl -i -X POST "{url}/${FILE}?override=true" \
-H "X-Auth: {auth_key}" \
-H "X-Auth-Rest: {rest_auth_key}" \
-H "Tus-Resumable: 1.0.0" \
-H "Upload-Length: ${SIZE}" \
-H "Upload-Offset: 0"
# -> 201 Created
curl -i -X PATCH "{url}/${FILE}?override=true" \
-H "X-Auth: {auth_key}" \
-H "X-Auth-Rest: {rest_auth_key}" \
-H "Tus-Resumable: 1.0.0" \
-H "Content-Type: application/offset+octet-stream" \
-H "Upload-Offset: 0" \
--data-binary "@${FILE}"
# -> 204 No Content, Upload-Offset response header equals SIZE when done
API Token authentication
Account username
u123456789Website domain
example.comSuccess response
The TUS upload endpoint URL to send upload requests to
https://srv12345-files.hstgr.io/Authentication token to pass as the X-Auth header in TUS upload requests
eYJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im15dXNlcm5hbWUiLCJkb21haW4iOiJteWRvbWFpbi5jb20iLCJpYXQiOjE2ODgwMjM2MDAsImV4cCI6MTY4ODA2MDgwMH0.4fXoX1HnY2b8jv7gX9h8vZ6xX3K1t7y5H3Z5Z5Z5Z5QAuthentication token to pass as the X-Auth-Rest header in TUS upload requests
d555be24e1096adcb6a029fbd1f25fdf18db587c5dbd01e0e49b22f67108b121-f496d493c2swfweaUnauthenticated response
Validation error response
Error response
POST /api/hosting/v1/files/upload-urls HTTP/1.1
Host: developers.hostinger.com
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json
Accept: */*
Content-Length: 48
{
"username": "u123456789",
"domain": "example.com"
}{
"url": "https://srv12345-files.hstgr.io/",
"auth_key": "eYJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im15dXNlcm5hbWUiLCJkb21haW4iOiJteWRvbWFpbi5jb20iLCJpYXQiOjE2ODgwMjM2MDAsImV4cCI6MTY4ODA2MDgwMH0.4fXoX1HnY2b8jv7gX9h8vZ6xX3K1t7y5H3Z5Z5Z5Z5Q",
"rest_auth_key": "d555be24e1096adcb6a029fbd1f25fdf18db587c5dbd01e0e49b22f67108b121-f496d493c2swfwea"
}Last updated
Was this helpful?