Skip to content

Backend overview ​

AnyDrop is a front-end library. It ships no server: your backend implements a small HTTP contract. Every field the client adds to an upload request has the ad prefix (adUploadId, adChunkIndex, ...).

The four endpoints ​

Your server implements these. Only the first is needed for plain uploads; the others switch on folders, resume and chunk assembly.

EndpointMethodOptionPurpose
/uploadPOST multiparturlOne chunk (file, adUploadId, adChunkIndex, adChunkSize, adChunkOffset, adTotalSize, ...), or a whole file when it is not chunked: then there are no chunk fields, only file and adRelativePath. Files up to chunkSize are sent whole even with chunking: true. Accept chunks in any order and more than once.
/upload/status?uploadId=GETchunkStatusUrl{ "received": [0, 1, 4] }, or { "received": [], "complete": true } once the file is assembled, or 404 if unknown. Lets the client resume.
/upload/manifestPOST JSONmanifestUrl (with sendManifest)The folders and files of a batch. Create every folder, including empty ones. A repeated manifest replaces the earlier one.
/upload/finalizePOST JSONfinalizeUrl{ uploadId, relativePath, totalSize, totalChunks }: assemble the chunks into the final file. Must be idempotent.

Errors are { "code": "...", "message": "..." } with an HTTP status; see the error table and the client-side error codes.

Optionally add HEAD /upload/ping (any status, Cache-Control: no-store) and set connectivityProbeUrl, so a dead network is detected quickly. See Offline and connectivity.

The matching client configuration ​

js
new AnyDrop('#uploader', {
  url: '/upload',
  chunking: true,
  chunkSize: 5 * 1024 * 1024,
  sendManifest: true,
  manifestUrl: '/upload/manifest',
  chunkStatusUrl: '/upload/status',
  finalizeUrl: '/upload/finalize',
  connectivityProbeUrl: '/upload/ping',
});

Security checklist ​

The examples are minimal. Before you use anything like them in production:

  • Authenticate every request, and check that an uploadId belongs to the current user.
  • Never build a file path from client input without checking it. The examples reject paths that are empty, absolute, contain \, or contain .. or empty segments.
  • Limit the size of a chunk, of a manifest request body (a manifest lists every file of a batch) and of the total storage per user.
  • Write chunks to a temporary name and rename them, so a cut-off write never counts as received.
  • If the page and the API are on different origins, answer the CORS preflight for GET, POST and HEAD, and allow the headers the client sends (X-Requested-With, Cache-Control, Content-Type and your own).
  • Check chunk lengths: a chunk whose length does not match adChunkSize (or the rest of the file for the last chunk) should be answered with 400 INVALID_CHUNK.

Released under the MIT License.