Uploading Files

API Endpoint

https://dev.interrupted.me/upload

Method

POST

Description

This endpoint allows you to upload a file to our servers. The file can be any file type and the maximum file size is 100MB.

Parameters

Below are the parameters you need to send to the endpoint.

ParameterTypeDescriptionRequiredMax size / Length
fileFileThe file you want to upload.Yes100MB
metadatastringAdditional metadata.No500 characters

Headers

Below are the headers you need to send to the endpoint.

HeaderValueDescription
AuthorizationBearer <token>Required. Your API token.
User-AgentstringRequired. Your user agent.
Content-Typemultipart/form-dataRequired. The content type.

Example Code Snippets

$url = "https://dev.interrupted.me/upload";
$file = "image.png"; // Path to the file you want to upload. In a real-world scenario, this would be a user-uploaded file.
$token = "YOUR_TOKEN_HERE";

// Our endpoint allows us to store metadata along with the file. For example you could store the user who uploaded the file.
$metadata = json_encode([
    'field1' => 'myusername',
    'field2' => 1,
]);

$ch = curl_init($url);

// Set the cURL options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // If set to true we can capture what our server responds

// Here we define the form-data parameters
$postFields = [
    'file' => new CURLFile($file, mime_content_type($file)), // !! IMPORTANT Specify the MIME type of the file you are uploading !!
    'metadata' => $metadata, // Optionally include metadata as JSON
];

// Set the form-data
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

// Only authenticated users can use our endpoint meaning that we need to include the token in the header and it should be prefixed with 'Bearer '. Otherwise the request will be rejected.
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $token,
]);

// This is the part where we execute the request itself and capture the response
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    // If everything went according to plan we can echo the response
    echo 'Response:' . $response;
}

// Close the cURL handle
curl_close($ch);

Example Response

{
    "file": {
        "id": 52,
        "user_id": 2,
        "file_name": "XGniSBUJ6vD2fgSF.jpg",
        "file_path": "dev/2/XGniSBUJ6vD2fgSF.jpg",
        "file_size": 17647,
        "metadata": "{\"value1\":\"hello world\"}"
    },
    "file_url": "https://devs.interrupted.me/dev/2/XGniSBUJ6vD2fgSF.jpg",
    "message": "File uploaded successfully"
}