{{define "api-file-post"}}
POST/file

Description

Upload a file.

Parameters

Param Type Required Maximum Size Default Description
name string false 255 Characters Multipart file name Name of the file to upload
anonymous boolean false N/A false If the file should be uploaded anonymously
file multipart file true 10 000 000 000 Bytes none Multipart file to upload

Returns

HTTP 200: OK
{
	"success": true,
	"id": "abc123" // ID of the newly uploaded file
}
HTTP 422: Unprocessable Entity
{
	"success": false,
	"value": "no_file",
	"message": "The file does not exist or is empty."
}
HTTP 500: Internal Server Error
{
	"success": false,
	"value": "internal",
	"message": "An internal server error occurred."
}
HTTP 413: Payload Too Large
{
	"success": false,
	"value": "file_too_large",
	"message": "The file you tried to upload is too large. Max 5000 MB allowed."
}
HTTP 500: Internal Server Error
{
	"success": false,
	"value": "writing",
	"message": "Something went wrong while writing the file to disk, the server may be out of storage space."
}
HTTP 413: Payload Too Large
{
	"success": false,
	"value": "name_too_long",
	"message": "File Name is too long, Max 255 characters allowed."
}
{{end}} {{define "api-file-id-get"}}
GET/file/{id}

Description

Returns the full file associated with the ID. Supports byte range requests.

When '?download' is added to the URL the server will send an attachment header instead of inline rendering, which causes the browser to show a 'Save File' dialog.

Parameters

Param Required Location Description
id true URL ID of the file to request
download false URL Sends file attachment instead of inline

Returns

A file output stream.
{{end}} {{define "api-file-id-info-get"}}
GET/file/{id}/info

Description

Returns information about one or more files. You can also put a comma separated list of file IDs in the URL and it will return an array of file info, instead of a single object.

Parameters

Param Required Location Description
id true URL ID(s) of the file

Returns

HTTP 200: OK
{
	"success": true,
	"id": "123abc",
	"name": "screenshot.png",
	"date_upload": 1485894987, // Timestamp
	"date_last_view": 1485894987, // Timestamp
	"size": 5694837, // Bytes
	"views" 1234, // Amount of unique file views
	"bandwidth_used": 1234567890, // Bytes
	"mime_type" "image/png",
	"description": "File description",
	"mime_image": "http://pixeldra.in/res/img/mime/image-png.png", // Image associated with the mime type
	"thumbnail": "http://pixeldra.in/api/thumbnail/123abc" // Link to a thumbnail of this file
}
HTTP 404: Not Found
{
	"success": false,
	"value": "file_not_found"
}
{{end}} {{define "api-file-id-thumbnail-get"}}
GET/file/{id}/thumbnail?width=x&height=x

Description

Returns a PNG thumbnail image representing the file. The thumbnail image will be 128x128 px by default. You can specify the width and height with parameters in the URL. The width and height parameters need to be a multiple of 16. So the allowed values are 16, 32, 48, 64, 80, 96, 112 and 128. If a thumbnail cannot be generated for the file you will be redirected to a mime type image of 128x128 px.

Parameters

Param Required Location Description
id true URL ID of the file to get a thumbnail for
width false URL Width of the thumbnail image
height false URL Height of the thumbnail image

Returns

A PNG image if a thumbnail can be generated. If a thumbnail cannot be generated you will get a 301 redirect to an image representing the type of the file.

{{end}} {{define "api-file-id-delete"}}
DELETE/file/{id}

Description

Deletes a file. Only works when the users owns the file.

Parameters

Param Required Location Description
id true URL ID of the file to delete

Returns

HTTP 200: OK
{
	"success": true,
	"value": "file_deleted",
	"message": "The file has been deleted."
}
HTTP 404: Not Found
{
	"success": false,
	"value": "file_not_found",
	"message": "File ID was not found in the database."
}
HTTP 401: Unauthorized
{
	"success": false,
	"value": "unauthorized",
	"message": "You are not logged in."
}
HTTP 403: Forbidden
{
	"success": false,
	"value": "forbidden",
	"message": "This is not your file."
}
{{end}}