importFile( )


Imports a file to the Media Manager using an external url.

Returns information about the imported file. Specify the parentFolderId and filePath parameters to specify which folder you want the file to be imported to. If no folder is specified, the file is imported to the media-root folder.

Notes:

  • The media property isn't returned in the files response object.
  • When you import a file, it's not immediately available, meaning you can't manage or use the file straight away. Learn more about knowing when a file is ready (SDK | REST).

To import a file, you need to do one of the following:

  • Specify its MIME type in the mimeType field of the request. For example, mimeType: 'image/jpeg'.
  • Specify its extension in either the displayName or url field of the request. For example, displayName: 'Example Image.jpeg or url: https://www.example.com/image.jpeg.
  • Ensure the server hosting the file supports HEAD requests. In these cases the Wix servers can retrieve the MIME type from the hosting server.

Note: If you want to validate the media type, specify the file's expected media type in the optional mediaType field of the request. For example, mediaType: 'IMAGE'.

Authentication
  • When developing websites or building an app with Blocks, this method may require elevated permissions, depending on the identity of the user calling it and the calling user’s permissions.
  • When building apps without Blocks or for headless projects, you can only call this method directly when authenticated as a Wix app or Wix user identity. When authenticated as a different identity, you can call this method using elevation.
  • Elevation permits users to call methods they typically cannot access. Therefore, you should only use it intentionally and securely.
Permissions
Manage Bookings Services and Settings
Manage Media Manager
Manage Events
Manage Portfolio
Access Verticals by Automations
Set Up Automations
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function importFile(
  url: string,
  options: ImportFileOptions,
): Promise<ImportFileResponse>;
Method Parameters
urlstringRequired

Publicly accessible external file URL.


optionsImportFileOptions

Options to use when importing a single file.

Returns
Return Type:Promise<ImportFileResponse>
JavaScript
import { files } from "@wix/media"; async function importFile(url, options) { const response = await files.importFile(url, options); }
Errors
400Invalid Argument

There is 1 error with this status code.

This method may also return standard errors. Learn more about standard Wix errors.

Did this help?