Uploading Using the Documents Library

The LEADTOOLS Documents library supports uploading documents from the user drive to the cache system. This support comes handy when the cache is hosted on a separate machine not accessible to the user. For example, when the Documents class is hosted in a web service with a JavaScript or rich client application. Such as the HTML5/JavaScript version of the LEADTOOLS Document Viewer using the LEADTOOLS Documents Web Service.

Uploading a document is supported only a valid instance of LEADTOOLS Cache Object is passed to DocumentFactory.UploadDocument or setup in the global DocumentFactory.Cache property.

All the methods for uploading a document are in the DocumentFactory class. Uploading the document can be done in chunks to show a progress bar and optionally allow the user to abort the application. Following are the steps required to perform this operation:

  1. The application should first prompt the user for the location of the document and then obtain a file stream object with read access to the original file.

  2. Create an instance of UploadDocumentOptions that can be populated with any optional values and then call the BeginUpload method. This method will return a temporary URL object to identity created by the DocumentFactory to identity this document for subsequent calls. This is a custom URL value in the following scheme leadcache://unique_guid_identifier and is not meant to be used by anything other than the rest of the upload methods. This value must be saved in the application in a local variable at this point.

  3. Read a chunk from the source file into a byte array. The size of this chunk is up to the user, the larger the chunk size, the shorter the whole upload operation but a too large of a chunk might throttle the server connection. A value of 64K is a good minimum. Once the chunk is read, call the DocumentFactory.UploadDocument method passing the URL value obtained from BeginUpload and the chunk of data.

  4. Repeat till all the file is read and uploaded. Then simply call the LoadFromUri method as usual when loading a document from a remote URL, the DocumentFactory class will check the value of the URL and can identity that this is an uploaded document that does not have access to the physical file and instead parses the document from the uploaded data. The data is stored in the cache and is disposed when the Document object is disposed and its cache items are expired.

  5. The upload URL is not needed once the Document object is obtained. The Document object itself and DocumentId are used as usual to interact with the document from this point on.

  6. At any point during uploading the document, DocumentFactory.AbortUploadDocument can be called to abort the operation and DocumentFactory will delete the data uploaded so far from the cache immediately.

For an example, refer to DocumentFactory.BeginUpload.

Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Imaging, Medical, and Document
Click or drag to resize