←Select platform

UploadDocument(ObjectCache,Uri,byte[],int,int) Method


Upload a chunk of the document to the specified cache.

public static void UploadDocument( 
   ObjectCache cache, 
   Uri uri, 
   byte[] data, 
   int offset, 
   int length 
   static void UploadDocument( 
      ObjectCache^ cache, 
      System::Uri^ uri, 
      array<Byte>^ data, 
      int offset, 
      int length 
public static void uploadDocument(ObjectCache cache, URI uri, byte[] data, int offset, int length) 
def UploadDocument(self,cache,uri,data,offset,length): 



The cache used when uploading this document. This value cannot be null.


The temporary document URI. This must be the same value returned from BeginUpload and cannot be null.


Current chunk of data. The factory will upload length number of bytes from this chunk starting at offset.


Offset into data where to data begins.


Number of bytes to upload.


BeginUpload, UploadDocument and AbortUploadDocument can be used to upload a document in chunks to the cache used by this DocumentFactory. After the document is uploaded, you can use LoadFromUri to create a LEADDocument object from the data.

Annotations for the document can also be uploaded using UploadAnnotations. This method must be called between BeginUpload and EndUpload.

Refer to Uploading Using the Document Library for detailed information on how to use these methods and the various options used.

using Leadtools; 
using Leadtools.Caching; 
using Leadtools.Document; 
public void DocumentFactoryBeginUploadExample() 
   var cache = GetCache(); 
   // Upload the document in 32K chunks 
   const int bufferSize = 1024 * 32; 
   var buffer = new byte[bufferSize]; 
   var fileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"); 
   Uri uploadUri = null; 
   using (var reader = File.OpenRead(fileName)) 
      // Start uploading 
      var uploadOptions = new UploadDocumentOptions(); 
      uploadOptions.Cache = cache; 
      // Optional: set the mime type of the document we are uploading. 
      // If this value is not provided or is wrong then it will be overridden by the factory when LoadFromUri is called. 
      uploadOptions.MimeType = "application/pdf"; 
      // Optional: set the name of the document, the same name as the file. 
      // This value is only important as a hint when the document file data does not contain a valid signature, such as TXT or XML files 
      uploadOptions.Name = "Leadtools.pdf"; 
      uploadOptions.CachePolicy = new CacheItemPolicy(); 
      uploadOptions.DocumentId = null; 
      uploadOptions.PageCount = 0; 
      uploadUri = DocumentFactory.BeginUpload(uploadOptions); 
      int bytes; 
         bytes = reader.Read(buffer, 0, bufferSize); 
         if (bytes > 0) 
            // Upload a chunk 
            DocumentFactory.UploadDocument(cache, uploadUri, buffer, 0, bytes); 
            // Upload annotations 
            DocumentFactory.UploadAnnotations(cache, uploadUri, buffer, 0, bytes); 
      while (bytes > 0); 
   // We are done, this method is optional, we can call LoadFromUri right now 
   DocumentFactory.EndUpload(cache, uploadUri); 
   // Now load the document 
   var options = new LoadDocumentOptions(); 
   options.Cache = cache; 
   using (var document = DocumentFactory.LoadFromUri(uploadUri, options)) 
static class LEAD_VARS 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 

Target Platforms

Help Version 22.0.2023.4.21
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.