uploadDocument Method

Summary

Uploads the specified data to the cache.

Syntax

JavaScript Syntax
uploadDocument = function(uri, data, offset, length) 
TypeScript Syntax
static uploadDocument(uri: string, data: any, offset: number, length: number): JQueryPromise<any>; 

Parameters

uri

The uri to upload to, which came from the result of BeginUpload.

data

The binary data, of JavaScript type ArrayBuffer, to upload.

offset

The position within data to get the chunk to upload.

length

The length of the chunk from data to upload, relative to offset.

Return Value

A voidPromise object that may resolve successfully.

Remarks

After BeginUpload has resolved and returned a uri, this method can be used to upload chunks of the document. BeginUpload, UploadDocument, and AbortUploadDocument are used together to get the same functionality as UploadFile, giving more control over the upload process. This method is often called in a loop to upload chunks of data to the cache over and over until the entire document has been uploaded. UploadDocument gives the developer control over when and how chunks are uploaded.

UploadDocument should not be called multiple times in a row without waiting for each call's Promise to be resolved, or the uploaded Document may be corrupt.

This method does not receive a DocumentUploadProgress object in the progress callback of the Promise.

Unlike with UploadFile, the Promise object returned by this method does not have an Abort method. Instead, AbortUploadDocument must be called with the same uploadUri being used to upload the document. This will not necessarily cause the Promise object from this method to fail immediately, but continued calls to UploadDocument will.

Please note that the browser must support the FileReader API in order to manipulate filesystem data on the client. If the FileReader API is not supported, an error will be thrown and IsBrowserError will return true.

Refer to Uploading Using LEADTOOLS Documents Library for more information on how to use this method.

Example

This example will download and then re-load a document from the service.

JavaScript Example
function uploadDownloadDocumentExample(doc) { 
   // doc is lt.Documents.Document object 
   var overall = []; 
   var dataSize = 1024 * 1024; 
   var location = 0; 
   var length = doc.values.fileLength; 
   var remaining = length; 
   console.log("File Length: " + length); 
   var done; 
   done = function (data) { 
      console.log("New data of length {0}", data.length); 
      overall = overall.concat(data); 
      location += data.length; 
      remaining = length - data.length; 
      if (remaining <= 0) { 
         // get an arraybuffer from the byte array 
         var uploadLength = overall.length; 
         var bytes = new Uint8Array(uploadLength); 
         overall.forEach(function (val, i) { 
            bytes[i] = val; 
         }); 
         var arrayBuffer = bytes.buffer; 
         // Done with downloading file. Now upload. 
         lt.Documents.DocumentFactory.beginUpload().done(function (uri) { 
            var filePosition = 0; 
            // if we aren't done, send the next request. 
            var doDone = function (userData) { 
               filePosition += dataSize; 
               if (filePosition < uploadLength) { 
                  lt.Documents.DocumentFactory.uploadDocument(uri, arrayBuffer, filePosition, dataSize).done(doDone); 
               } 
               else { 
                  // Fully uploaded 
                  // done, load the document 
                  lt.Documents.DocumentFactory.loadFromUri(uri, null) 
                      .done(function (doc) { 
                         console.log("Document was loaded succesfully"); 
                      }); 
               } 
            }; 
            // Upload next part 
            lt.Documents.DocumentFactory.uploadDocument(uri, arrayBuffer, filePosition, dataSize).done(doDone); 
         }); 
      } 
      else { 
         // Download it 
         lt.Documents.DocumentFactory.downloadDocument(doc.documentId, null, location, dataSize) 
             .done(done); 
      } 
   }; 
   // Download it 
   lt.Documents.DocumentFactory.downloadDocument(doc.documentId, null, location, dataSize) 
       .done(done); 
} 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Documents Assembly