Files
You can actually host files on Interclip, here is the documentation for all of that.
#
Storing filesThe files are kept in an S3 bucket hosted somewhere in the cloud. There is a retention policy for all files, so they are deleted after a certain time. This time is set to 69 days to prevent usage of Interclip as a CDN or backup service.
#
FrontendThere is a simple interface at /file
which is powered by a JS script, which upon selection of a file (drag n' drop, input selection, or pasting of an image) does these things:
- Checks if the file isn't over the
fileSizeLimitInMegabytes
limit - Starts a
XMLHttpRequest()
(please don't kill me for not usingfetch()
, butXMLHttpRequest()
let's me update the progress bar) - Updates the progress bar on every
onprogress
event - If the upload succeeds, it creates a form (along with an anti-CSRF token and the returned URL) and submits it to
includes/new
, where the user gets a code for their file
#
Backend#
PHPThe file upload script for all uploads is here: https://github.com/aperta-principium/Interclip/blob/main/upload/index.php
What it does is it takes the uploaded_file
from the $_FILES
superglobal and:
- Checks if the file is above the file size limit
- Creates a unique identifier for the file, getting the first 10 characters of a SHA1, which is generated from the
uniqid()
with the seed of the current timestamp joined with a random shuffle of the alphanumeric alphabet. This method does not check for duplicates because it would impact performance. There is about 3 quadrillion (3.656158440062976 × 10^15) possible combinations of file ids. - The extension of the file is scanned for illegal characters (anything non-ASCII basically)
- If it doesn't contain any, it moves the file from its
tmp_name
toupload/uploads/
under the new name - It executes
upload.sh
with an argument as the path of the newly uploaded file in the background - It renders the URL in plaintext and exits
upload.sh
#
The upload script does thee uploading in two easy steps:
- It copies the file to the cloud storage server via
rclone
- It removes the original file
#
The file reverse-proxy#
LimitationsThere are currently 2 major limitations to Interclip files:
- The file proxy is deployed to Cloudflare workers and has a limit of 100K requests daily (if you want to bring Interclip files down, this is your way to go)
- The server is limited to 20TB of file uploads per month, which means, that users can upload a max of about 200K 3MB images per day.