API

Client

To simplify uploading and deleting files, you can use linx-client, which uses this API.

Keys

This instance uses API Keys, therefore you will need to provide a key for uploading and deleting files.
To do so, add the Linx-Api-Key header with your key, or supply it as a standard Bearer token in an Authorization header, or pass it as the Linx-Api-Key query parameter.

Uploading a file

To upload a file, make a PUT or POST request to https://sh.c5h.io/upload/ and you will get the url of your upload back.

PUT uploads send the file as the request body and optionally specify a filename in the URL (e.g. https://sh.c5h.io/upload/myphoto.jpg).

POST uploads support three formats:

  • Multipart form (Content-Type: multipart/form-data) with a file field
  • URL-encoded form (Content-Type: application/x-www-form-urlencoded) with content and extension fields
  • Raw body — send the file directly as the request body (like PUT), with metadata via query parameters: filename, expires, access_key, randomize

Optional headers with the request

Specify a custom deletion key
Linx-Delete-Key: mysecret

Protect file with password
Linx-Access-Key: mysecret

Specify an expiration time (in seconds)
Linx-Expiry: 60

Get a json response
Accept: application/json

The json response will then contain:

“url”: the publicly available upload url
“direct_url”: the url to access the file directly
“filename”: the (optionally generated) filename
“delete_key”: the (optionally generated) deletion key,
“access_key”: the (optionally supplied) access key,
“expiry”: the unix timestamp at which the file will expire (0 if never)
“size”: the size in bytes of the file
“mimetype”: the guessed mimetype of the file
“sha256sum”: the sha256sum of the file,

Alternatively, add the redirect query parameter to receive a 201 Created response with a Location header pointing to the direct file URL.

Examples

Uploading myphoto.jpg

$ curl -H "Linx-Api-Key: mysecretkey" -T myphoto.jpg https://sh.c5h.io/upload/
https://sh.c5h.io/7z4h4ut.jpg

Uploading myphoto.jpg with an expiry of 20 minutes

$ curl -H "Linx-Api-Key: mysecretkey" -H "Linx-Expiry: 1200" -T myphoto.jpg https://sh.c5h.io/upload/
https://sh.c5h.io/jm295snf.jpg

Uploading myphoto.jpg with a random filename and getting a json response:

$ curl -H "Linx-Api-Key: mysecretkey" -H "Accept: application/json" -T myphoto.jpg https://sh.c5h.io/upload/
{"delete_key":"...","expiry":"0","filename":"f34h4iu.jpg","mimetype":"image/jpeg",
"sha256sum":"...","size":"...","url":"https://sh.c5h.io/f34h4iu.jpg"}

Overwriting a file

To overwrite a file you uploaded, simply provide the Linx-Delete-Key header with the original file's deletion key.

Example

To overwrite myphoto.jpg

$ curl -H "Linx-Api-Key: mysecretkey" -H "Linx-Delete-Key: mysecret" -T myphoto.jpg https://sh.c5h.io/upload/
https://sh.c5h.io/myphoto.jpg

Deleting a file

To delete a file you uploaded, make a DELETE request to https://sh.c5h.io/yourfile.ext with the delete key set as the Linx-Delete-Key header.

Example

To delete myphoto.jpg

$ curl -H "Linx-Api-Key: mysecretkey" -H "Linx-Delete-Key: mysecret" -X DELETE https://sh.c5h.io/myphoto.jpg
DELETED

Information about a file

To retrieve information about a file, make a GET request the public url with Accept: application/json headers and you will receive a json response containing:

“url”: the publicly available upload url
“direct_url”: the url to access the file directly
“filename”: the (optionally generated) filename
“expiry”: the unix timestamp at which the file will expire (0 if never)
“size”: the size in bytes of the file
“mimetype”: the guessed mimetype of the file
“sha256sum”: the sha256sum of the file,

Example

$ curl -H "Accept: application/json" https://sh.c5h.io/myphoto.jpg
{"expiry":"0","filename":"myphoto.jpg","mimetype":"image/jpeg","sha256sum":"...","size":"..."}