Search.../

generateFileUploadUrl( )

Developer Preview

Generates an upload URL to allow external clients to upload a file to the Media Manager.

Description

The generateFileUploadUrl() function returns a Promise that resolves to an upload URL.

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

Note: Any interruption in the upload process stops the file upload. For files larger than 10MB, or when network connection is poor, use generateFileResumableUploadUrl() instead. With the resumable upload URL, any interruption in the upload process pauses the file upload, and resumes the file upload process after the interruption.

Admin Method

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

Syntax

function generateFileUploadUrl(mimeType: string, options: GenerateFileUploadUrlOptions): Promise<GenerateFileUploadUrlResponse>

generateFileUploadUrl Parameters

NAME
TYPE
DESCRIPTION
mimeType
string

File mime type.

options
Optional
GenerateFileUploadUrlOptions

Options to use when generating a file's upload URL.

Returns

Return Type:

Promise<
GenerateFileUploadUrlResponse
>
NAME
TYPE
DESCRIPTION
uploadUrl
string

The URL for uploading a file to the Media Manager.

Was this helpful?

Generate a file upload url

Copy Code
1import { files } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample mimeType value: 'image/jpeg'
5 * Sample options value:
6 * {
7 * fileName: 'image1.jpeg',
8 * parentFolderId: '103601562ec94214bee61f470b403dd5',
9 * labels: ['nature', 'outdoors']
10 * }
11 */
12
13async function myGenerateFileUploadUrlFunction(mimeType, options) {
14 try {
15 const elevatedGenerateFileUploadUrl = elevate(files.generateFileUploadUrl);
16 const result = await elevatedGenerateFileUploadUrl(mimeType, options);
17
18 const url = result.uploadUrl;
19 return url;
20 } catch (error) {
21 console.error(error);
22 // Handle the error
23 }
24}
25
26/* Promise resolves to:
27 * {
28 * "uploadUrl": "https://upload.wixmp.com/upload/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzYTk0N2E5Ni01ZmFiLTQ0NjAtODVkNS1hNTIxNWRjNzRiMjEiLCJhdWQiOiJ1cm46c2VydmljZTp1cGxvYWQiLCJpc3MiOiJ1cm46c2VydmljZT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xKZldHSTVja3Q1U0hadWRVSkxRMlJ1VWpCQlZGOTJjVnB5U2s5T1ZWbE1UM0JTVEU1bFExTlhjVzQzUzA1V2RuTjBVR2RyU3paMllXTnVjbTlRWDA5MGFTMUdOamRrU2tWelpWZFJhM0I2VW5WUGNIQkpTa1ZUUTJkMVpERkZRa2xOYlUxM1RWcGhWUzB4YUhoUk5HcFdWR2h2V1VJMU5FRnFhSGRpWlZSemRVbEVSRGxFT1dWWGVtaG5VVGhQZUV3MWVHdElORXN3UTFOWE5qSkRRazlQUlVrOUluMHNJbWhsWVdSbGNuTWlPbTUxYkd3c0luQmhjM04wYUhKdmRXZG9JanAwY25WbGZYMC5iRWJSTzdnYkQxaXR0TW9Hb29QUTBsbDZrbW5jSEdfc05pRjRXZzFZWTc0IiwiYWNsIjoicHVibGljIiwibWltZVR5cGUiOiJpbWFnZS9qcGVnIn0.pd9ZssMw0NOTIxmNm0gm3r5WP6ySCy4vBxlT8ufU_Vw"
29 * }
30 */
Use a file upload url in an external node.js 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}