Search.../

upload( )

Uploads a file to the Media Manager from a buffer.

Description

The upload() function returns a Promise that resolves to information about the newly uploaded file.

Video and audio files that have been uploaded aren't immediately available to be used even after the Promise is resolved. Before they can be used, they must first undergo transcoding. The onFileUploaded() event is triggered when a file has been uploaded and before the transcoding is finished.

To import a file to the Media Manager directly from a URL, use the importFile() function.

To enable site visitors to upload files to your site, you can also use an upload button.

Note: There are limits on the size and duration of files that you can upload. See Wix Media: Supported Media File Types and File Sizes for more details.

Syntax

function upload(path: string, fileContent: Buffer, fileName: string, options: UploadOptions): FileInfo

upload Parameters

NAME
TYPE
DESCRIPTION
path
string

The path within the Media Manager where the file will be uploaded.

If the path doesn't yet exist, the missing folders will be created, for example: /media/files.

If metadataOptions.isVisitorUpload is true (default), the visitor-uploads folder is the root of the file path, in this case, visitor-uploads/media/files/.

fileContent
Buffer

Buffer containing the content to be uploaded.

fileName
string

In this case the fileName is the name you would like your file to appear as in the Media Manager.

options
UploadOptions

Options to use when uploading the file.

Returns

Fulfilled - Information about the file that was uploaded.

Return Type:

Promise<FileInfo>
NAME
TYPE
DESCRIPTION
fileName
string

Deprecated. Use the fileUrl property instead.

The fileName property is the internal name (unique identifier) which is generated when a file is uploaded by the Media Manager, returned from the importFile(), or upload() functions. The name is the string located in the file's URL. Click here to learn more. Use this name when calling the getFileInfo(), getFileUrl(), and getVideoPlaybackUrl() functions.

fileUrl
string

The file's Wix media URL in the following format: 'wix:image://v1/<uri>/<filename>#originWidth=<width>&originHeight=<height>[&watermark=<watermark_manifest_string>]'.

hash
string

File hash.

sizeInBytes
number

Size of the uploaded file in bytes.

mimeType
string

Mime type of the uploaded file.

mediaType
string

Type of the file that was uploaded. One of:

  • "audio"
  • "document"
  • "image"
  • "shape"
  • "video"
isPrivate
boolean

Whether the link to the uploaded file is public or private. Private links require a token to be used.

parentFolderId
string

ID of the file's parent folder.

originalFileName
string

Original name of the uploaded file. This is the display name that appears in the Media Manager.

opStatus
string

Status of the file that was uploaded. One of:

  • "IN-DOWNLOAD-QUEUE"
  • "IN-QUEUE"
  • "READY"
sourceURL
string

URL where the file was uploaded from.

iconUrl
string

URL of the file's icon.

labels
Array<string>

List of labels assigned to the file by the Media Manager.

height
string

Media height.

width
string

Media width.

_createdDate
Date

Date the file was created.

_updatedDate
Date

Date the file was updated.

Was this helpful?

Upload a file

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { mediaManager } from 'wix-media-backend';
3
4export const uploadImage = webMethod(Permissions.Anyone, (buffer) => {
5 return mediaManager.upload(
6 "/myUploadFolder/subfolder",
7 buffer,
8 "myFileName.jpg",
9 {
10 "mediaOptions": {
11 "mimeType": "image/jpeg",
12 "mediaType": "image"
13 },
14 "metadataOptions": {
15 "isPrivate": false,
16 "isVisitorUpload": false,
17 "context": {
18 "someKey1": "someValue1",
19 "someKey2": "someValue2"
20 }
21 }
22 }
23 );
24});
25
26/* Returns a promise that resolves to:
27 * {
28 * "mediaType": "image",
29 * "isPrivate": false,
30 * "sizeInBytes": 51085,
31 * "mimeType": "image/jpeg",
32 * "iconUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
33 * "fileUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
34 * "originalFileName": "myFileName.jpg",
35 * "hash": "bee2f8aab80b0d011499361c2eb189eb",
36 * "labels": [
37 * "Blue",
38 * "Butterfly",
39 * "Turquoise"
40 * ],
41 * "width": 300,
42 * "height": 300
43 * }
44 */