> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # ImportFile # Package: channels # Namespace: CommunicationChannelsMedia # Method link: https://dev.wix.com/docs/api-reference/crm/communication/channels/communication-channels-media/import-file.md ## Permission Scopes: Manage Inbox Messages: SCOPE.DC-INBOX.MANAGE-MSGS ## Introduction Imports a file from an external URL directly into the Media Manager. Call this method to import files from external URLs into the Media Manager, such as files hosted on another site or server. To import a file, you need to do one of the following: - Specify its [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) 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, Wix servers can retrieve the MIME type from the hosting server. > **Notes:** > - 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'`. > - 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](https://dev.wix.com/docs/api-reference/assets/media/media-manager/files/importing-files.md#knowing-when-a-file-is-ready) to use in the Media Manager. --- ## REST API ### Schema ``` Method: importFile Description: Imports a file from an external URL directly into the Media Manager. Call this method to import files from external URLs into the Media Manager, such as files hosted on another site or server. To import a file, you need to do one of the following: - Specify its [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) 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, Wix servers can retrieve the MIME type from the hosting server. > **Notes:** > - 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'`. > - 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](https://dev.wix.com/docs/api-reference/assets/media/media-manager/files/importing-files.md#knowing-when-a-file-is-ready) to use in the Media Manager. URL: https://www.wixapis.com/v1/import-file Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: url, mimeType Method parameters: param name: displayName | type: displayName | description: Display name for the file in the Media Manager. If not specified, file name is extracted from the URL. param name: mimeType | type: mimeType | description: File mime type. | required: true param name: url | type: url | description: Publicly accessible URL for the file to import. | required: true param name: urlHeaders | type: urlHeaders | description: Optional headers to send with the import request. param name: urlParams | type: urlParams | description: Optional URL parameters to send with the import request. Return type: ImportFileResponse - name: fileId | type: string | description: File GUID. Generated when a file is uploaded to the Media Manager. - name: displayName | type: string | description: Display name of the file as it appears in the Media Manager. - name: url | type: string | description: Static URL for accessing the imported file. - name: sizeInBytes | type: string | description: Size of the imported file in bytes. Possible Errors: HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILE_FORMAT | Description: File format not supported. HTTP Code: 500 | Status Code: INTERNAL | Application Code: FILE_DESCRIPTOR_NOT_FOUND | Description: File descriptor not found. ``` ### Examples ### Import a file ```curl curl -X POST \ 'https://www.wixapis.com/communication-channels-media/v1/import-file' \ -H 'Authorization: ' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.channels.CommunicationChannelsMedia.importFile(url, options) Description: Imports a file from an external URL directly into the Media Manager. Call this method to import files from external URLs into the Media Manager, such as files hosted on another site or server. To import a file, you need to do one of the following: - Specify its [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) 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, Wix servers can retrieve the MIME type from the hosting server. > **Notes:** > - 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'`. > - 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](https://dev.wix.com/docs/api-reference/assets/media/media-manager/files/importing-files.md#knowing-when-a-file-is-ready) to use in the Media Manager. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: url, options.mimeType, options Method parameters: param name: options | type: ImportFileOptions none | required: true - name: displayName | type: string | description: Display name for the file in the Media Manager. If not specified, file name is extracted from the URL. - name: mimeType | type: string | description: File mime type. | required: true - name: urlParams | type: object | description: Optional URL parameters to send with the import request. - name: urlHeaders | type: object | description: Optional headers to send with the import request. param name: url | type: string | description: Publicly accessible URL for the file to import. | required: true Return type: PROMISE - name: fileId | type: string | description: File GUID. Generated when a file is uploaded to the Media Manager. - name: displayName | type: string | description: Display name of the file as it appears in the Media Manager. - name: url | type: string | description: Static URL for accessing the imported file. - name: sizeInBytes | type: string | description: Size of the imported file in bytes. Possible Errors: HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: UNSUPPORTED_FILE_FORMAT | Description: File format not supported. HTTP Code: 500 | Status Code: INTERNAL | Application Code: FILE_DESCRIPTOR_NOT_FOUND | Description: File descriptor not found. ``` ### Examples ### importFile ```javascript import { communicationChannelsMedia } from '@wix/comm-channels-media'; async function importFile(url,options) { const response = await communicationChannelsMedia.importFile(url,options); }; ``` ### importFile (with elevated permissions) ```javascript import { communicationChannelsMedia } from '@wix/comm-channels-media'; import { auth } from '@wix/essentials'; async function myImportFileMethod(url,options) { const elevatedImportFile = auth.elevate(communicationChannelsMedia.importFile); const response = await elevatedImportFile(url,options); } ``` ### importFile (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { communicationChannelsMedia } from '@wix/comm-channels-media'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { communicationChannelsMedia }, // Include the auth strategy and host as relevant }); async function importFile(url,options) { const response = await myWixClient.communicationChannelsMedia.importFile(url,options); }; ``` ---