Attempts to load a file from a Blob or File object.
loadFromFile = function(file)
file
The uploaded resource to load.
The file will be routed to the appropriate registry based off the Content-Type for the resource. If no registry exists for the Content-Type of the resource, or if there is no default registry handler, an error will be thrown.
export class ContentManager_Load {
protected manager: lt.ContentManager.ContentManager = null;
private pdfUrl = 'https://demo.leadtools.com/images/pdf/leadtools.pdf';
private pngUrl = 'https://demo.leadtools.com/images/png/ocr1.png';
public constructor() {
// Set the LEADTOOLS license. Replace this with your actual license file
lt.RasterSupport.setLicenseUri("https://demo.leadtools.com/licenses/js/LEADTOOLSEVAL.txt", "EVAL", null);
this.manager = new lt.ContentManager.ContentManager();
this.setup();
this.addClickEvents();
}
private addClickEvents = () => {
const loadPdfBtn = document.getElementById('loadPdf');
const loadPngBtn = document.getElementById('loadPng');
const loadLocal = document.getElementById('loadLocal');
loadPdfBtn.onclick = () => this.manager.loadFromUri(this.pdfUrl);
loadPngBtn.onclick = () => this.manager.loadFromUri(this.pngUrl);
loadLocal.onchange = (e: any) => {
const file = e.target.files[0];
if (!file)
return;
this.manager.loadFromFile(file);
}
}
private setup = () => {
const registry = this.manager.registry;
// The ContentManager's allow you to specify precise workflows for different content types.
// First, we will create a specific handler for PNG files.
registry.register({
mimetypes: ['image/png'],
onLoadFromFile: this.onLocalPng,
onLoadFromUri: this.onUriPng
});
// We are also able to create a default handler
// The ContentManager will prioritize handlers in the following order:
// 1. Specific content type matches
// 2. Default handler
registry.register({
default: true,
mimetypes: [],
onLoadFromFile: this.onLocalDefault,
onLoadFromUri: this.onUriDefault
})
}
private onLocalDefault(blob: File | Blob) {
alert('Upload default triggered!')
}
private onUriDefault(url: string) {
alert('Default URI load triggered!');
}
private onLocalPng(blob: File | Blob) {
alert('Uploaded PNG triggered!');
}
private onUriPng(url: string) {
alert('PNG URI load triggered!');
}
}