Uploads a new document with options to the server in one shot.
uploadFileDocument =function(
blob,
uploadOptions
)
staticuploadFileDocument(
blob: Blob,
uploadOptions:UploadDocumentOptions
):AbortableJqueryPromise;
blob
The JavaScriptBlob
/File
object representing the file to upload.
uploadOptions
Options to use with the new document. This value cannot benull.
APromiseobject that can resolve successfully to a special uri pointing to the location of the newly-createdLEADDocumentin the cache (verifiable withIsUploadDocumentUri). The returned Promise has a unique type ofAbortableJQueryPromisethat holds theabortmethod.
When the value ofUploadDocumentOptions.documentIdisnull(the default), then the document factory will create a new, unique ID using a GUID generator. If the value is notnull, then it is assumed to be a user-defined ID and used as is. In either case, the value is set in theLEADDocument.DocumentIdproperty of the newly created document.
User-defined IDs can be used when the system already has unique IDs associated with the documents to be viewer. The document factory will neither check nor guarantee the uniqueness of these IDs.
TheUploadFileDocumentmethod is an abstraction of three other methods used together to manage the upload of a resource, as follows:
UploadFileDocumentwraps together the functionality of these three methods, and returns a url to the uploaded resource when thePromiseresolves. This url can be used to load the document withLoadFromUri.
The data is uploaded in chunks and the size of each chunk uploaded is determined byuploadBlobChunkSize.
ThePromisefor this method can receive progress events. Refer toDocumentUploadProgressfor more information.
ThePromiseobject that is returned immediately by callingUploadFileDocumentis of typeAbortableJQueryPromise, an extension of the usual jQuery Promise object. This class adds an additional method,Abort, which has the same functionality asAbortUploadDocumentbut is not static, and thus does not need the uri of the uploading file. If the upload is aborted, thefail
callback to thePromiseobject will be called with all three parameters set asnull. SeePromisesfor more information.
This method uses the JavaScriptFile
object to obtain access to a file on the local machine.
Note that the browser must support theFileReader APIin order to manipulate file system data on the local machine. If theFileReader
API is not supported, an error will be thrown andIsBrowserErrorwill returntrue.
Refer toUploading Using the Document Libraryfor detailed information on how to use this method and the various options used.
This example will upload a file from the local machine and then download it as a LEADTOOLS Document object ready to be used.
import{ DocumentHelper } from"../../utilities/DocumentHelper";
exportclassDocumentFactory_UploadFileDocumentExample {
publicconstructor() {
lt.RasterSupport.setLicenseUri("https://demo.leadtools.com/licenses/v200/LEADTOOLSEVAL.txt","EVAL",null);
DocumentHelper.initFactory();
}
publicrun = (buttonID:string) => {
constexampleButton = document.getElementById(buttonID);
// Add a file select
constfileInput = document.createElement("input");
fileInput.type ="file";
exampleButton.parentNode.appendChild(fileInput);
// add an "upload" button
constuploadButton = document.createElement("button");
uploadButton.type ="button";
uploadButton.innerHTML ="Click to Upload";
exampleButton.parentNode.appendChild(uploadButton);
uploadButton.onclick = () => {
constfile = fileInput.files[0];
if(!file) {
alert("No file!");
return;
}
// Upload it
DocumentHelper.log("Uploading...");
// Create upload options
let uploadDocumentOptions =newlt.Document.UploadDocumentOptions();
// Enable streaming on the server
uploadDocumentOptions.enableStreaming =true;
lt.Document.DocumentFactory.uploadFileDocument(file, uploadDocumentOptions)
.done((uri) => {
// Done, now load it
DocumentHelper.log("Finished uploading. Now loading...");
constloadDocumentOptions =newlt.Document.LoadDocumentOptions();
// Set the name
loadDocumentOptions.name = file.name;
lt.Document.DocumentFactory.loadFromUri(uri, loadDocumentOptions)
.done((doc) => {
DocumentHelper.log("Document was loaded successfully");
DocumentHelper.log("Name is "+ doc.name);
DocumentHelper.log("MIMEType is "+ doc.mimeType);
DocumentHelper.log("Number of Pages is "+ doc.pages.count);
})
.fail(DocumentHelper.showServiceError);
})
.fail(DocumentHelper.showServiceError);
}
}
}
exportclassDocumentHelper {
staticshowServiceError = (jqXHR, statusText, errorThrown) => {
alert(“从服务返回错误。看到控制台details.");
constserviceError = lt.Document.ServiceError.parseError(jqXHR, statusText, errorThrown);
console.error(serviceError);
}
staticlog = (message:string, data?:any) => {
constoutputElement = document.getElementById("output");
if(outputElement) {
consttime = (newDate()).toLocaleTimeString();
consttextElement = document.createElement("p");
textElement.innerHTML = (outputElement.childElementCount + 1) +" ["+ time +"]: "+ message;
outputElement.insertBefore(textElement, outputElement.firstChild);
}
if(!data)
console.log(message);
else
console.log(message, data);
}
staticinitFactory = () => {
// To communicate with the DocumentsService, it must be running!
// Change these parameters to match the path to the service.
lt.Document.DocumentFactory.serviceHost ="http://localhost:40000";
lt.Document.DocumentFactory.servicePath ="";
lt.Document.DocumentFactory.serviceApiPath ="api";
}
}
import{ DocumentHelper } from"../../utilities/DocumentHelper";
exportclassDocumentFactory_UploadFileDocumentExample {
constructor() {
lt.RasterSupport.setLicenseUri("https://demo.leadtools.com/licenses/v200/LEADTOOLSEVAL.txt","EVAL",null);
DocumentHelper.initFactory();
}
run = (buttonID) => {
constexampleButton = document.getElementById(buttonID);
// Add a file select
constfileInput = document.createElement("input");
fileInput.type ="file";
exampleButton.parentNode.appendChild(fileInput);
// add an "upload" button
constuploadButton = document.createElement("button");
uploadButton.type ="button";
uploadButton.innerHTML ="Click to Upload";
exampleButton.parentNode.appendChild(uploadButton);
uploadButton.onclick = () => {
constfile = fileInput.files[0];
if(!file) {
alert("No file!");
return;
}
// Upload it
DocumentHelper.log("Uploading...");
// Create upload options
let uploadDocumentOptions =newlt.Document.UploadDocumentOptions();
// Enable streaming on the server
uploadDocumentOptions.enableStreaming =true;
lt.Document.DocumentFactory.uploadFileDocument(file, uploadDocumentOptions)
.done((uri) => {
// Done, now load it
DocumentHelper.log("Finished uploading. Now loading...");
constloadDocumentOptions =newlt.Document.LoadDocumentOptions();
// Set the name
loadDocumentOptions.name = file.name;
lt.Document.DocumentFactory.loadFromUri(uri, loadDocumentOptions)
.done((doc) => {
DocumentHelper.log("Document was loaded successfully");
DocumentHelper.log("Name is "+ doc.name);
DocumentHelper.log("MIMEType is "+ doc.mimeType);
DocumentHelper.log("Number of Pages is "+ doc.pages.count);
})
.fail(DocumentHelper.showServiceError);
})
.fail(DocumentHelper.showServiceError);
}
}
}
exportclassDocumentHelper {
staticshowServiceError = (jqXHR, statusText, errorThrown) => {
alert(“从服务返回错误。看到控制台details.");
constserviceError = lt.Document.ServiceError.parseError(jqXHR, statusText, errorThrown);
console.error(serviceError);
}
staticlog = (message, data) => {
constoutputElement = document.getElementById("output");
if(outputElement) {
consttime = (newDate()).toLocaleTimeString();
consttextElement = document.createElement("p");
textElement.innerHTML = (outputElement.childElementCount + 1) +" ["+ time +"]: "+ message;
outputElement.insertBefore(textElement, outputElement.firstChild);
}
if(!data)
console.log(message);
else
console.log(message, data);
}
staticinitFactory = () => {
// To communicate with the DocumentsService, it must be running!
// Change these parameters to match the path to the service.
lt.Document.DocumentFactory.serviceHost ="http://localhost:40000";
lt.Document.DocumentFactory.servicePath ="";
lt.Document.DocumentFactory.serviceApiPath ="api";
}
}
"en">
Document Example | UploadFileDocument <链接rel="stylesheet"type="text/css"href="../../css/examples.css">
"output">
"img"/>
window.onload = () => {
constexample =newwindow.examples.DocumentFactory.UploadFileDocument();
example.run("exampleButton");
};
Help Collections
Raster.NET|C API|C++ Class Library|HTML5 JavaScript
Document.NET|C API|C++ Class Library|HTML5 JavaScript
Medical.NET|C API|C++ Class Library|HTML5 JavaScript
Medical Web Viewer.NET
188宝金博怎么下载
Media Foundation.NET|C API|Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.