Leadtools.Documents Namespace > DocumentFactory Object : UploadDocument Method |
ArrayBuffer
, to upload.
Parameter | Type | Description |
---|---|---|
uri | string | The uri to upload to, which came from the result of BeginUpload. |
data | object | The binary data, of JavaScript type ArrayBuffer , to upload. |
offset | int | The position within data to get the chunk to upload. |
length | int | The length of the chunk from data to upload, relative to offset. |
Type | Description |
---|---|
jQueryApi.IDeferred | A void Promise object that may resolve succesfully. |
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.
function uploadDownloadDocumentExample(document) { // document is lt.Documents.Document object var overall = []; var dataSize = 1024 * 1024; var location = 0; var length = document.values.fileLength; var remaining = length; demo.Output.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 (document) { DocumentsTest.log.success("Document was loaded succesfully"); }); } }; // Upload next part lt.Documents.DocumentFactory.uploadDocument(uri, arrayBuffer, filePosition, dataSize).done(doDone); }); } else { // Download it lt.Documents.DocumentFactory.downloadDocument(document.documentId, null, location, dataSize) .done(done); } }; // Download it lt.Documents.DocumentFactory.downloadDocument(document.documentId, null, location, dataSize) .done(done); }