> 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: bulkImportFile(importFileRequests: Array, options: BulkImportFileOptions) # Method package: wixMediaV2 # Method menu location: wixMediaV2 --> files --> bulkImportFile # Method Link: https://dev.wix.com/docs/velo/apis/wix-media-v2/files/bulk-import-file.md # Method Description: Imports a bulk of files to the Media Manager using external urls.
Returns information about the imported files. Specify the `parentFolderId` and `filePath` parameters to specify the folder you want each 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 files, you need to do one of the following for each file: - 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'`. - Include 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. ## Bulk import file (dashboard page code) ```javascript import { files } from 'wix-media.v2'; /* Sample importFileRequests value: * [ * { * displayName: 'image1', * mediaType: 'IMAGE', * mimeType: 'image/jpeg', * parentFolderId: 'igje5u22nij3qkltzsnol37j3dnthvvh', * url: 'https://www.site1.com/example.jpg' * }, * { * displayName: 'vectorArt1', * mediaType: 'VECTOR', * labels : ['label1', 'label2'], * url: 'https://cdn.vectorstock.com/example-vector-art.webp' * }, * { * displayName: 'video1', * mediaType: 'VIDEO', * url: 'https://cdn.pixabay.com/example-video.mp4' * } * ] */ async function mybulkImportFileFunction(importFileRequests) { try { const importedFiles = await files.bulkImportFile(importFileRequests); console.log("Imported files:", importedFiles); return importedFiles; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "bulkActionMetadata": { * "totalFailures": 0, * "totalSuccesses": 3, * "undetailedFailures": 0 * }, * "results": [ * { * "item": { * "_createdDate": "2023-12-26T10:22:31.000Z", * "_id": "a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg", * "_updatedDate": "2023-12-26T10:22:31.000Z", * "addedBy": { * "identityId": "a8a52bb9-bac0-4bba-a55c-0611b5cdaa16", * "identityType": "MEMBER" * }, * "displayName": "image1.jpg", * "hash": "", * "internalTags": [], * "labels": [], * "mediaType": "IMAGE", * "operationStatus": "PENDING", * "parentFolderId": "igje5u22nij3qkltzsnol37j3dnthvvh", * "private": false, * "siteId": "49dcb500-1081-47b0-b13b-368b9bed8fa9", * "sizeInBytes": "-1", * "sourceUrl": "https://www.site1.com/example.jpg", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg", * "url": "https://static.wixstatic.com/media/a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg" * }, * "itemMetadata": { * "_id": "a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg", * "originalIndex": 0, * "success": true * } * }, * { * "item": { * "_createdDate": "2023-12-26T10:22:32.000Z", * "_id": "a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg", * "_updatedDate": "2023-12-26T10:22:32.000Z", * "addedBy": { * "identityId": "a8a52bb9-bac0-4bba-a55c-0611b5cdaa16", * "identityType": "MEMBER" * }, * "displayName": "vectorArt1.webp.svg", * "hash": "", * "internalTags": [], * "labels": ["label1", "label2"], * "mediaType": "VECTOR", * "operationStatus": "PENDING", * "parentFolderId": "media-root", * "private": false, * "siteId": "49dcb500-1081-47b0-b13b-368b9bed8fa9", * "sizeInBytes": "-1", * "sourceUrl": "https://cdn.vectorstock.com/example-vector-art.webp", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/shapes/a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg", * "url": "https://static.wixstatic.com/shapes/a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg" * }, * "itemMetadata": { * "_id": "a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg", * "originalIndex": 1, * "success": true * } * }, * { * "item": { * "_createdDate": "2023-12-26T10:22:32.000Z", * "_id": "a8a52b_fec67a695b474a729e3a31010afbb0af", * "_updatedDate": "2023-12-26T10:22:32.000Z", * "addedBy": { * "identityId": "a8a52bb9-bac0-4bba-a55c-0611b5cdaa16", * "identityType": "MEMBER" * }, * "displayName": "video1.mp4", * "hash": "", * "internalTags": [], * "labels": [], * "mediaType": "VIDEO", * "operationStatus": "PENDING", * "parentFolderId": "media-root", * "private": false, * "siteId": "49dcb500-1081-47b0-b13b-368b9bed8fa9", * "sizeInBytes": "-1", * "sourceUrl": "https://cdn.pixabay.com/example-video.mp4", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/54ece48fa04e492fa46bd79980105f0d.png", * "url": "https://video.wixstatic.com/video/a8a52b_fec67a695b474a729e3a31010afbb0af/file" * }, * "itemMetadata": { * "_id": "a8a52b_fec67a695b474a729e3a31010afbb0af", * "originalIndex": 2, * "success": true * } * } * ] * } */ ``` ## Bulk import 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 importFileRequests value: * [ * { * displayName: 'image1', * mediaType: 'IMAGE', * mimeType: 'image/jpeg', * parentFolderId: 'igje5u22nij3qkltzsnol37j3dnthvvh', * url: 'https://www.site1.com/example.jpg' * }, * { * displayName: 'vectorArt1', * mediaType: 'VECTOR', * labels : ['label1', 'label2'], * url: 'https://cdn.vectorstock.com/example-vector-art.webp' * }, * { * displayName: 'video1', * mediaType: 'VIDEO', * url: 'https://cdn.pixabay.com/example-video.mp4' * } * ] */ export const mybulkImportFileFunction = webMethod(Permissions.Anyone, async (importFileRequests) => { try { const elevatedbulkImportFile = elevate(files.bulkImportFile) const importedFiles = await elevatedbulkImportFile(importFileRequests); console.log("Imported files:", importedFiles); return importedFiles; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "bulkActionMetadata": { * "totalFailures": 0, * "totalSuccesses": 3, * "undetailedFailures": 0 * }, * "results": [ * { * "item": { * "_createdDate": "2023-12-26T10:22:31.000Z", * "_id": "a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg", * "_updatedDate": "2023-12-26T10:22:31.000Z", * "addedBy": { * "identityId": "a8a52bb9-bac0-4bba-a55c-0611b5cdaa16", * "identityType": "MEMBER" * }, * "displayName": "image1.jpg", * "hash": "", * "internalTags": [], * "labels": [], * "mediaType": "IMAGE", * "operationStatus": "PENDING", * "parentFolderId": "igje5u22nij3qkltzsnol37j3dnthvvh", * "private": false, * "siteId": "49dcb500-1081-47b0-b13b-368b9bed8fa9", * "sizeInBytes": "-1", * "sourceUrl": "https://www.site1.com/example.jpg", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg", * "url": "https://static.wixstatic.com/media/a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg" * }, * "itemMetadata": { * "_id": "a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg", * "originalIndex": 0, * "success": true * } * }, * { * "item": { * "_createdDate": "2023-12-26T10:22:32.000Z", * "_id": "a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg", * "_updatedDate": "2023-12-26T10:22:32.000Z", * "addedBy": { * "identityId": "a8a52bb9-bac0-4bba-a55c-0611b5cdaa16", * "identityType": "MEMBER" * }, * "displayName": "vectorArt1.webp.svg", * "hash": "", * "internalTags": [], * "labels": ["label1", "label2"], * "mediaType": "VECTOR", * "operationStatus": "PENDING", * "parentFolderId": "media-root", * "private": false, * "siteId": "49dcb500-1081-47b0-b13b-368b9bed8fa9", * "sizeInBytes": "-1", * "sourceUrl": "https://cdn.vectorstock.com/example-vector-art.webp", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/shapes/a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg", * "url": "https://static.wixstatic.com/shapes/a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg" * }, * "itemMetadata": { * "_id": "a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg", * "originalIndex": 1, * "success": true * } * }, * { * "item": { * "_createdDate": "2023-12-26T10:22:32.000Z", * "_id": "a8a52b_fec67a695b474a729e3a31010afbb0af", * "_updatedDate": "2023-12-26T10:22:32.000Z", * "addedBy": { * "identityId": "a8a52bb9-bac0-4bba-a55c-0611b5cdaa16", * "identityType": "MEMBER" * }, * "displayName": "video1.mp4", * "hash": "", * "internalTags": [], * "labels": [], * "mediaType": "VIDEO", * "operationStatus": "PENDING", * "parentFolderId": "media-root", * "private": false, * "siteId": "49dcb500-1081-47b0-b13b-368b9bed8fa9", * "sizeInBytes": "-1", * "sourceUrl": "https://cdn.pixabay.com/example-video.mp4", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/54ece48fa04e492fa46bd79980105f0d.png", * "url": "https://video.wixstatic.com/video/a8a52b_fec67a695b474a729e3a31010afbb0af/file" * }, * "itemMetadata": { * "_id": "a8a52b_fec67a695b474a729e3a31010afbb0af", * "originalIndex": 2, * "success": true * } * } * ] * } */ ``` ## Bulk import 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 importFileRequests value: * [ * { * displayName: 'image1', * mediaType: 'IMAGE', * mimeType: 'image/jpeg', * parentFolderId: 'igje5u22nij3qkltzsnol37j3dnthvvh', * url: 'https://www.site1.com/example.jpg' * }, * { * displayName: 'vectorArt1', * mediaType: 'VECTOR', * labels : ['label1', 'label2'], * url: 'https://cdn.vectorstock.com/example-vector-art.webp' * }, * { * displayName: 'video1', * mediaType: 'VIDEO', * url: 'https://cdn.pixabay.com/example-video.mp4' * } * ] */ export const mybulkImportFileFunction = webMethod(Permissions.Anyone, async (importFileRequests, options) => { try { const elevatedbulkImportFile = elevate(files.bulkImportFile) const importedFiles = await elevatedbulkImportFile(importFileRequests, options); console.log("Imported files:", importedFiles); return importedFiles; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "bulkActionMetadata": { * "totalFailures": 0, * "totalSuccesses": 3, * "undetailedFailures": 0 * }, * "results": [ * { * "item": { * "_createdDate": "2023-12-26T10:22:31.000Z", * "_id": "a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg", * "_updatedDate": "2023-12-26T10:22:31.000Z", * "addedBy": { * "identityId": "a8a52bb9-bac0-4bba-a55c-0611b5cdaa16", * "identityType": "MEMBER" * }, * "displayName": "image1.jpg", * "hash": "", * "internalTags": [], * "labels": [], * "mediaType": "IMAGE", * "operationStatus": "PENDING", * "parentFolderId": "igje5u22nij3qkltzsnol37j3dnthvvh", * "private": false, * "siteId": "49dcb500-1081-47b0-b13b-368b9bed8fa9", * "sizeInBytes": "-1", * "sourceUrl": "https://www.site1.com/example.jpg", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg", * "url": "https://static.wixstatic.com/media/a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg" * }, * "itemMetadata": { * "_id": "a8a52b_f8c86723942347488316f1ab35119411~mv2.jpg", * "originalIndex": 0, * "success": true * } * }, * { * "item": { * "_createdDate": "2023-12-26T10:22:32.000Z", * "_id": "a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg", * "_updatedDate": "2023-12-26T10:22:32.000Z", * "addedBy": { * "identityId": "a8a52bb9-bac0-4bba-a55c-0611b5cdaa16", * "identityType": "MEMBER" * }, * "displayName": "vectorArt1.webp.svg", * "hash": "", * "internalTags": [], * "labels": ["label1", "label2"], * "mediaType": "VECTOR", * "operationStatus": "PENDING", * "parentFolderId": "media-root", * "private": false, * "siteId": "49dcb500-1081-47b0-b13b-368b9bed8fa9", * "sizeInBytes": "-1", * "sourceUrl": "https://cdn.vectorstock.com/example-vector-art.webp", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/shapes/a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg", * "url": "https://static.wixstatic.com/shapes/a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg" * }, * "itemMetadata": { * "_id": "a8a52b_43eb6841371f4d738ddfcb7fa2bb62be-tmp.svg", * "originalIndex": 1, * "success": true * } * }, * { * "item": { * "_createdDate": "2023-12-26T10:22:32.000Z", * "_id": "a8a52b_fec67a695b474a729e3a31010afbb0af", * "_updatedDate": "2023-12-26T10:22:32.000Z", * "addedBy": { * "identityId": "a8a52bb9-bac0-4bba-a55c-0611b5cdaa16", * "identityType": "MEMBER" * }, * "displayName": "video1.mp4", * "hash": "", * "internalTags": [], * "labels": [], * "mediaType": "VIDEO", * "operationStatus": "PENDING", * "parentFolderId": "media-root", * "private": false, * "siteId": "49dcb500-1081-47b0-b13b-368b9bed8fa9", * "sizeInBytes": "-1", * "sourceUrl": "https://cdn.pixabay.com/example-video.mp4", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/54ece48fa04e492fa46bd79980105f0d.png", * "url": "https://video.wixstatic.com/video/a8a52b_fec67a695b474a729e3a31010afbb0af/file" * }, * "itemMetadata": { * "_id": "a8a52b_fec67a695b474a729e3a31010afbb0af", * "originalIndex": 2, * "success": true * } * } * ] * } */ ``` ## Bulk import files from visitor input into a form ```javascript /**************************************** * Backend code - bulk-import-files.web.js * ***************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; export const importFiles = webMethod(Permissions.Anyone, async (importFileRequests) => { try { const elevatedBulkImportFile = elevate(files.bulkImportFile) const importedFiles = await elevatedBulkImportFile(importFileRequests); console.log("Imported files:", importedFiles); return importedFiles; } catch (error) { console.error(error); // Handle the error } }); /************* * Page code * ************/ import { importFiles } from 'backend/bulk-import-files.web'; $w.onReady(() => { const newMedia = []; $w('#addMedia').onClick( () => { const newMediaFile = { displayName: $w('#displayName').value, mediaType: $w('#mediaType').value, parentFolderId: $w('#parentFolderId').value, url: $w('#url').value } newMedia.push(newMediaFile); // show message to remind user to submit media // after adding all media files for 5 seconds $w('#rememberToUploadMessage').show(); setTimeout(() => { $w('#rememberToUploadMessage').hide(); }, 5000) }); $w('#uploadMedia').onClick(async () => { if (newMedia.length === 0) { // if no media has been added then // show message to add media $w('#addMediaMsg').show() } else { await importFiles(newMedia); $w('#successfulUploadMsg').show(); setTimeout(() => { $w('#successfulUploadMsg').hide(); }, 10000); } }); }); ``` ---