Search.../

generateFileResumableUploadUrl( )

Developer Preview

Generates a resumable upload URL to allow external clients to upload large files over 10MB to the Media Manager.

Description

The generateFileResumableUploadUrl() function returns a Promise that resolves to an upload URL, token, and protocol.

When using the resumable upload URL, any interruptions will pause the file upload process, which automatically resumes once the interruption is resolved. The resumable upload URL is also helpful when network connection is poor.

To learn how external clients can use the generated upload URL in the response to upload large files to the Media Manager, see the Resumable Upload API article.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function generateFileResumableUploadUrl(mimeType: string, options: GenerateFileResumableUploadUrlOptions): Promise<GenerateFileResumableUploadUrlResponse>

generateFileResumableUploadUrl Parameters

NAME
TYPE
DESCRIPTION
mimeType
string

File mime type.

options
Optional
GenerateFileResumableUploadUrlOptions

Options to use when generating a resumable upload URL.

Returns

Return Type:

Promise<
GenerateFileResumableUploadUrlResponse
>
NAME
TYPE
DESCRIPTION
uploadProtocol
string

The upload protocol to use for implementing the resumable upload.

Supported values: "TUS"

uploadToken
string

Single-use upload token.

uploadUrl
string

The URL for uploading a file to the Media Manager.

Was this helpful?

Generate a file resumable upload url

Copy Code
1import { files } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample mimeType value: 'image/jpeg'
5 *
6 * Sample options value:
7 * {
8 * fileName: 'image1.jpeg',
9 * parentFolderId: '103601562ec94214bee61f470b403dd5',
10 * labels: ['nature', 'outdoors']
11 * }
12 */
13
14async function myGenerateFileResumableUploadUrlFunction(mimeType, options) {
15 try {
16 const elevatedGenerateFileResumableUploadUrl = elevate(files.generateFileResumableUploadUrl);
17 const result = await elevatedGenerateFileResumableUploadUrl(mimeType, options);
18
19 return result;
20 } catch (error) {
21 console.error(error);
22 // Handle the error
23 }
24}
25
26/* Promise resolves to:
27 * {
28 * "uploadProtocol": "TUS",
29 * "uploadToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlMWIwNTkxYi0wMTQyLTRkOTctYjg2My1lOTQwN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application

Copy Code
1/********************************
2 * External Node.js application *
3 *******************************/
4
5import axios from 'axios';
6
7/* Sample fileName value: 'video1.mp4'
8 * Sample contentType value: 'video/mp4'
9 * Sample videoToUpload value: 'path/to/yourVideo.mp4'
10 */
11
12async function myUploadVideoFunction(generatedUploadUrl, videoToUpload, fileName, contentType) {
13 const response = await axios.put(generatedUploadUrl, videoToUpload, {
14 headers: {
15 'Content-Type': contentType
16 },
17 params: {
18 filename: fileName
19 }
20 });
21
22 return `${response[0].uploadUrl}`;
23}