Search.../

importFile( )

Imports a file to the Media Manager from a URL.

Description

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

Video and audio files that have been imported 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 an imported file has been uploaded and before the transcoding is finished. As a result, some properties such as the fileUrl may not initially appear in the returns.

Syntax

function importFile(path: string, url: string, options: UploadOptions): FileInfo

importFile 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/.

url
string

The file's external URL, where it was imported from.

options
UploadOptions

Options to use when uploading a 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?

Import a file

Copy Code
1import { mediaManager } from 'wix-media-backend';
2
3export function importFile(url) {
4 return mediaManager.importFile(
5 "/myImportFolder/subfolder",
6 url,
7 {
8 "mediaOptions": {
9 "mimeType": "image/jpeg",
10 "mediaType": "image"
11 },
12 "metadataOptions": {
13 "isPrivate": false,
14 "isVisitorUpload": false,
15 "context": {
16 "someKey1": "someValue1",
17 "someKey2": "someValue2"
18 }
19 }
20 }
21 );
22}
23
24/* Returns a promise that resolves to:
25 *
26 * {
27 * "fileUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/imported-pic.png#originWidth=319&originHeight=206",
28 * "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
29 * "sizeInBytes": 51085,
30 * "mimeType": "image/jpeg",
31 * "mediaType": "image",
32 * "isPrivate": false,
33 * "parentFolderId": "2bf470f5be194b319cdb2accc3278ff9",
34 * "originalFileName": "my-image.jpg",
35 * "sourceUrl": "https://somedomain.com/img/original-name.jpg",
36 * "opStatus": "IN-DOWNLOAD-QUEUE"
37 * }
38 */