Appearance
Mobile Web Capture API Reference / ExportConfig
Interface: ExportConfig
Handlers that connect Mobile Web Capture's export features to your own server.
Remarks
Which features appear in the UI depends on which handlers are defined:
- ExportConfig.uploadToServer alone adds an Upload button to the
DocumentViewandPageView(and theLibraryView, when enabled). - Defining
uploadToServer, ExportConfig.downloadFromServer, and ExportConfig.deleteFromServer together additionally enables Upload History in theLibraryView.
See
Example
javascript
const uploadToServer = async (fileName, blob) => {
const formData = new FormData();
formData.append("uploadFile", blob, fileName);
const response = await fetch(`${window.location.origin}/upload`, {
method: "POST",
body: formData,
});
// Returning { status: "success" } is required to trigger onUploadSuccess.
return { status: response.status === 200 ? "success" : "failed" };
};
const mobileWebCapture = new Dynamsoft.MobileWebCapture({
license: "YOUR_LICENSE_KEY_HERE",
exportConfig: {
uploadToServer,
onUploadSuccess: async (fileName) => {
console.log(`${fileName} uploaded successfully!`);
return true; // Close the Mobile Web Capture instance
},
},
});Properties
deleteFromServer?
optionaldeleteFromServer?: (doc) =>Promise<void>
Deletes a previously uploaded document from your server.
Parameters
doc
The document the user selected, as returned by uploadToServer.
Returns
Promise<void>
Remarks
Called when the user deletes a document from the upload history. Required, together with ExportConfig.uploadToServer and ExportConfig.downloadFromServer, to enable Upload History.
downloadFromServer?
optionaldownloadFromServer?: (doc) =>Promise<void>
Downloads a previously uploaded document from your server.
Parameters
doc
The document the user selected, as returned by uploadToServer.
Returns
Promise<void>
Remarks
Called when the user picks a document in the upload history. Required, together with ExportConfig.uploadToServer and ExportConfig.deleteFromServer, to enable Upload History.
onUploadSuccess?
optionalonUploadSuccess?: (fileName,fileType,view,blob) =>Promise<boolean>
Runs after an upload reports success.
Parameters
fileName
string
Name of the uploaded file.
fileType
string
MIME type of the uploaded file.
view
The View the upload was started from.
blob
The uploaded file contents.
Returns
Promise<boolean>
true to close the Mobile Web Capture instance after the upload, false to leave it open.
Remarks
Only called when ExportConfig.uploadToServer resolved with status: "success".
uploadToServer?
optionaluploadToServer?: (fileName,blob) =>Promise<void|UploadedDocument>
Uploads a document or page to your server.
Parameters
fileName
string
Name of the file being uploaded.
blob
The file contents — a multi-page PDF for a document, a PNG for a single page.
Returns
Promise<void | UploadedDocument>
Remarks
Defining this handler is what puts the Upload button in the UI. Resolve with an UploadedDocument whose status is "success" to trigger ExportConfig.onUploadSuccess and to list the document in the upload history; resolving with void uploads without either.