To upload a file to a site's Media Manager with a URL that allows you to pause and resume an upload, you can call Generate File Resumable Upload URL. This call returns a signed uploadUrl and uploadToken that you can then use to upload a file.
Notes:
The code for generating an upload URL and sending it an upload request varies depending on your context. For example, the code for a dashboard page of a self-hosted app differs slightly from the code for a headless site.
However, in all scenarios, you need to perform the following steps:
To create a resumable upload experience, use a tus client. There are tus client implementations available for many popular languages.
After generating an uploadUrl by calling Generate File Resumable Upload URL, use a tus client to create a tus upload with the following information:
endpoint: The uploadUrl returned from the call to Generate File Resumable Upload URL.metadata Specify the following metadata:
filename: The name of the file to upload.contentType: The MIME type of the file to upload.token: The upload token returned from the call to Generate File Resumable Upload URL.After the tus upload completes successfully, call the uploadUrl using the following information:
uploadUrl followed by a / and the uploadToken.filename with the name of the file, including the extension. The filename parameter is optional if fileName was already provided in the Generate File Resumable Upload URL call.Note: You need to determine the file's MIME type before uploading. For example, in Node.js you can use the mime-types library or the file-type package. Other languages and platforms have equivalent libraries for detecting MIME types.
When the upload is successful, Wix returns information about the file being uploaded.
Uploading files takes time. Receiving a successful response from a call to the uploadUrl doesn't mean that the upload is complete. To run code when the upload finishes, listen for the File Ready and File Failed events. Learn more about knowing when a file is ready.
The following example code shows the calls to generate a resumable upload URL and use it to upload an image file. How you make those calls depends on the context in which you're writing that code.
You also need to write code that performs the other steps in the upload flow to retrieve the information you need to provide when making the calls shown below.
To generate an upload URL, you need to send a POST request to Generate File Resumable Upload URL, specifying the MIME type of the file.
The response contains a signed uploadUrl and an uploadToken.
After generating an uploadUrl and uploadToken, use a tus client to upload the file. When the tus upload completes, make a PUT request to finalize the upload.
This example uses tus-js-client to implement the resumable upload:
A call to a generated uploadUrl returns a response structured as follows: