UNPKG

@esri/solution-common

Version:

Provides general helper functions for @esri/solution.js.

40 lines 1.9 kB
import { createCopyResults } from "./createCopyResults"; import { getBlob } from "./get-blob"; import { updateItem as helpersUpdateItem } from "../restHelpers"; // ------------------------------------------------------------------------------------------------------------------ // /** * Copies data into an AGO item. * * @param fileInfo Information about the source and destination of the file such as its URL, folder, filename * @param sourceAuthentication Credentials for the request to the source * @param destinationItemId Id of item to receive copy of resource/metadata/thumbnail * @param destinationAuthentication Credentials for the request to the storage * @returns A promise which resolves to the result of the copy */ export function copyDataIntoItem(fileInfo, sourceAuthentication, destinationItemId, destinationAuthentication) { return new Promise((resolve) => { getBlob(fileInfo.url, sourceAuthentication).then((blob) => { const update = { id: destinationItemId, data: createMimeTypedFile({ blob: blob, filename: fileInfo.filename, mimeType: fileInfo.mimeType || blob.type, }), }; helpersUpdateItem(update, destinationAuthentication, fileInfo.folder).then(() => resolve(createCopyResults(fileInfo, true, true)), () => resolve(createCopyResults(fileInfo, true, false))); }, () => resolve(createCopyResults(fileInfo, false))); }); } /** * Creates a file with a specified mime type. * * @param fileDescription Structure containing a file and the desired mime type * @returns Created file */ export function createMimeTypedFile(fileDescription) { return new File([fileDescription.blob], fileDescription.filename, { type: fileDescription.mimeType, }); } //# sourceMappingURL=copyDataIntoItem.js.map