> 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 # Method name: importFile(url: string, options: ImportFileOptions) # Method package: wixMediaV2 # Method menu location: wixMediaV2 --> files --> importFile # Method Link: https://dev.wix.com/docs/velo/apis/wix-media-v2/files/import-file.md # Method Description: 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](https://dev.wix.com/docs/sdk/backend-modules/media/files/importing-files.md#backend-modules_media_files_knowing-when-a-file-is-ready) | [REST](https://dev.wix.com/docs/rest/assets/media/media-manager/files/importing-files.md#knowing-when-a-file-is-ready)). 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 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'`. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Import a file (dashboard page code) ```javascript import { files } from 'wix-media.v2'; /* Sample url value: 'https://example.org/filename.jpg' */ async function myImportFileFunction(url) { try { const importedFile = await files.importFile(url); console.log('Imported file successfully:', importedFile); return importedFile; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "file": { * "_createdDate": "2023-07-23T09:19:05.000Z", * "_id": "w8ide0_leac4pwk8o11v8725j9ugcbe70x3alc0~mv2.jpg", * "_updatedDate": "2023-07-23T09:19:05.000Z", * "displayName": "image1.jpg", * "hash": "", * "internalTags": [], * "labels": [], * "mediaType": "IMAGE", * "operationStatus": "PENDING", * "parentFolderId": "media-root", * "private": false, * "sizeInBytes": "20167", * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sourceUrl": "https://example.org/filename.jpg", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/w8ide0_leac4pwk8o11v8725j9ugcbe70x3alc0~mv2.jpg", * "url": "https://static.wixstatic.com/media/w8ide0_leac4pwk8o11v8725j9ugcbe70x3alc0~mv2.jpg" * } * } */ ``` ## Import a file (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; // Sample url value: 'https://example.org/filename.jpg' export const myImportFileFunction = webMethod(Permissions.Anyone, async (url) => { try { const elevatedImportFile = elevate(files.importFile); const importedFile = await elevatedImportFile(url); console.log('Imported file successfully:', importedFile); return importedFile; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "file": { * "_createdDate": "2023-07-23T09:19:05.000Z", * "_id": "w8ide0_leac4pwk8o11v8725j9ugcbe70x3alc0~mv2.jpg", * "_updatedDate": "2023-07-23T09:19:05.000Z", * "displayName": "image1.jpg", * "hash": "", * "internalTags": [], * "labels": [], * "mediaType": "IMAGE", * "operationStatus": "PENDING", * "parentFolderId": "media-root", * "private": false, * "sizeInBytes": "20167", * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sourceUrl": "https://example.org/filename.jpg", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/w8ide0_leac4pwk8o11v8725j9ugcbe70x3alc0~mv2.jpg", * "url": "https://static.wixstatic.com/media/w8ide0_leac4pwk8o11v8725j9ugcbe70x3alc0~mv2.jpg" * } * } */ ``` ## Import a file with options ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; // Sample url value: 'https://example.org/filename.jpg' export const myImportFileFunction = webMethod(Permissions.Anyone, async (url, importOptions) => { try { const elevatedImportFile = elevate(files.importFile); const importedFile = await elevatedImportFile(url, importOptions); console.log('Imported file successfully:', importedFile); return importedFile; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "file": { * "_createdDate": "2023-07-23T09:19:05.000Z", * "_id": "w8ide0_leac4pwk8o11v8725j9ugcbe70x3alc0~mv2.jpg", * "_updatedDate": "2023-07-23T09:19:05.000Z", * "displayName": "image1.jpg", * "hash": "", * "internalTags": [], * "labels": [], * "mediaType": "IMAGE", * "operationStatus": "PENDING", * "parentFolderId": "media-root", * "private": false, * "sizeInBytes": "20167", * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sourceUrl": "https://example.org/filename.jpg", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/w8ide0_leac4pwk8o11v8725j9ugcbe70x3alc0~mv2.jpg", * "url": "https://static.wixstatic.com/media/w8ide0_leac4pwk8o11v8725j9ugcbe70x3alc0~mv2.jpg" * } * } */ ``` ---