←Select platform

BeginUpload Method (DocumentFactory)

Summary

Start uploading a document to the cache.

Syntax

C#
VB
Java
C++
public static System.Uri BeginUpload( 
   UploadDocumentOptions options 
) 
Public Shared Function BeginUpload( 
   ByVal options As UploadDocumentOptions 
) As System.Uri 
public:  
   static System::Uri^ BeginUpload( 
      UploadDocumentOptions^ options 
   ) 
public static URI beginUpload(UploadDocumentOptions options)

Parameters

options

Options to use with the new document. This value cannot be null.

Return Value

The temporary URL for the uploaded document.

Remarks

This method will throw an exception if neither LoadDocumentOptions.Cache nor Cache was setup with a valid cache object.

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 Document object from the data.

This method returns a URL with a special LEAD cache scheme to indicate a loaded document. This URL can be detected using IsUploadDocumentUri helper method.

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

Example

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
using Leadtools.Documents; 
using Leadtools.Caching; 
using Leadtools.Annotations.Core; 
using Leadtools.Forms.Ocr; 
using Leadtools.Barcode; 
 
       
public static void DocumentFactoryBeginUploadExample()    
{ 
   var cache = GetCache(); 
   const int bufferSize = 1024 * 32; 
   var buffer = new byte[bufferSize]; 
 
   var fileName = Path.Combine(ImagesPath.Path, "Leadtools.pdf"); 
   Uri uploadUri = null; 
   using (var reader = File.OpenRead(fileName)) 
   { 
      var uploadOptions = new UploadDocumentOptions(); 
      uploadOptions.Cache = cache; 
      uploadUri = DocumentFactory.BeginUpload(uploadOptions); 
 
      int bytes; 
      do 
      { 
         bytes = reader.Read(buffer, 0, bufferSize); 
         if (bytes > 0) 
         { 
            DocumentFactory.UploadDocument(cache, uploadUri, buffer, 0, bytes); 
         } 
      } 
      while (bytes > 0); 
   } 
 
   var options = new LoadDocumentOptions(); 
   options.Cache = cache; 
   using (var document = DocumentFactory.LoadFromUri(uploadUri, options)) 
   { 
      PrintOutDocumentInfo(document); 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms.DocumentWriters 
Imports Leadtools.Svg 
Imports Leadtools.Documents 
Imports Leadtools.Caching 
Imports Leadtools.Annotations.Core 
Imports Leadtools.Barcode 
Imports Leadtools.Forms.Ocr 
 
<TestMethod()> 
Public Shared Sub DocumentFactoryBeginUploadExample() 
   Dim cache As ObjectCache = GetCache() 
   Const bufferSize As Integer = 1024 * 32 
   Dim buffer() As Byte = New Byte(bufferSize - 1) {} 
 
   Dim fileName As String = Path.Combine(ImagesPath.Path, "Leadtools.pdf") 
   Dim uploadUri As Uri = Nothing 
   Using reader As FileStream = File.OpenRead(fileName) 
      Dim uploadOptions As New UploadDocumentOptions() 
      uploadOptions.Cache = cache 
      uploadUri = DocumentFactory.BeginUpload(uploadOptions) 
 
      Dim bytes As Integer 
      Do 
         bytes = reader.Read(buffer, 0, bufferSize) 
         If bytes > 0 Then 
            DocumentFactory.UploadDocument(cache, uploadUri, buffer, 0, bytes) 
         End If 
      Loop While bytes > 0 
   End Using 
 
   Dim options As New LoadDocumentOptions() 
   options.Cache = cache 
   Using document As Leadtools.Documents.Document = DocumentFactory.LoadFromUri(uploadUri, options) 
      PrintOutDocumentInfo(document) 
   End Using 
End Sub 

Requirements

Target Platforms

Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
Leadtools.Documents Assembly
Click or drag to resize