Starts uploading a document to the cache.
public static 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)
options
Options to use with the new document. This value cannot be null.
The temporary URL for the uploaded document.
This method will throw an exception if neither UploadDocumentOptions.Cache nor Cache has been set up 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 LEADDocument object from the data.
When uploading is finished, EndUpload must be called to inform the factory that the uploading process has finished.
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 Document Library for detailed information on how to use these methods and the various options available.
using Leadtools;using Leadtools.Codecs;using Leadtools.Document.Writer;using Leadtools.Document;using Leadtools.Caching;using Leadtools.Annotations.Engine;using Leadtools.Ocr;using Leadtools.Barcode;using Leadtools.Document.Converter;public void DocumentFactoryBeginUploadExample(){var cache = GetCache();// Upload the document in 32K chunksconst 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 uploadingvar 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 filesuploadOptions.Name = "Leadtools.pdf";uploadUri = DocumentFactory.BeginUpload(uploadOptions);int bytes;do{bytes = reader.Read(buffer, 0, bufferSize);if (bytes > 0){// Upload a chunkDocumentFactory.UploadDocument(cache, uploadUri, buffer, 0, bytes);}}while (bytes > 0);}// We are done, this method is optional, we can call LoadFromUri right nowDocumentFactory.EndUpload(cache, uploadUri);// Now load the documentvar options = new LoadDocumentOptions();options.Cache = cache;using (var document = DocumentFactory.LoadFromUri(uploadUri, options)){PrintOutDocumentInfo(document);}}public void PrintOutDocumentInfo(LEADDocument document){Console.WriteLine("General");Console.WriteLine(" DocumentId:" + document.DocumentId);if (document.Uri != null)Console.WriteLine(" Uri:" + document.Uri);Console.WriteLine(" Name:" + document.Name);Console.WriteLine(" CacheStatus:" + document.CacheStatus);Console.WriteLine(" LastCacheSyncTime:" + document.LastCacheSyncTime);Console.WriteLine(" IsReadOnly:" + document.IsReadOnly);Console.WriteLine(" IsLocal:" + document.IsLocal);Console.WriteLine(" MimeType:" + document.MimeType);Console.WriteLine(" IsEncrypted:" + document.IsEncrypted);Console.WriteLine(" IsDecrypted:" + document.IsDecrypted);Console.WriteLine(" UserData:" + document.UserData);Console.WriteLine("Cache");Console.WriteLine(" HasCache:" + document.HasCache);Console.WriteLine(" AutoDeleteFromCache:" + document.AutoDeleteFromCache);Console.WriteLine("Metadata");foreach (var item in document.Metadata)Console.WriteLine(" {0} {1}", item.Key, item.Value);Console.WriteLine("Documents");Console.WriteLine(" Count:" + document.Documents.Count);foreach (var childDocument in document.Documents){Console.WriteLine(" Name:" + childDocument.Name);}Console.WriteLine("Pages");Console.WriteLine(" Count:" + document.Pages.Count);for (var pageNumber = 1; pageNumber <= document.Pages.Count; pageNumber++){var page = document.Pages[pageNumber - 1];Console.WriteLine(" PageNumber:" + pageNumber);Console.WriteLine(" OriginalPageNumber:" + page.OriginalPageNumber);Console.WriteLine(" OriginalDocumentName:" + page.Document.Name);Console.WriteLine(" Size:{0}", page.Size);}Console.WriteLine("--------");}public ObjectCache GetCache(){// Create a LEADTOOLS FileCache objectvar cacheDir = Path.Combine(LEAD_VARS.ImagesDir, "cache");if (Directory.Exists(cacheDir))Directory.Delete(cacheDir, true);Directory.CreateDirectory(cacheDir);var cache = new FileCache();cache.CacheDirectory = cacheDir;return cache;}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Document.WriterImports Leadtools.SvgImports Leadtools.DocumentImports Leadtools.CachingImports Leadtools.Annotations.EngineImports Leadtools.BarcodeImports Leadtools.OcrImports LeadtoolsDocumentExamples.LeadtoolsExamples.CommonImports Leadtools.Document.ConverterPublic Shared Sub DocumentFactoryBeginUploadExample()Dim cache As ObjectCache = GetCache()' Upload the document in 32K chunksConst bufferSize As Integer = 1024 * 32Dim buffer() As Byte = New Byte(bufferSize - 1) {}Dim fileName As String = Path.Combine(ImagesPath.Path, "Leadtools.pdf")Dim uploadUri As Uri = NothingUsing reader As FileStream = File.OpenRead(fileName)' Start uploadingDim uploadOptions As 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 filesuploadOptions.Name = "Leadtools.pdf"uploadUri = DocumentFactory.BeginUpload(uploadOptions)Dim bytes As IntegerDobytes = reader.Read(buffer, 0, bufferSize)If bytes > 0 Then' Upload a chunkDocumentFactory.UploadDocument(cache, uploadUri, buffer, 0, bytes)End IfLoop While bytes > 0End Using' We are done, this method Is optional, we can call LoadFromUri right nowDocumentFactory.EndUpload(cache, uploadUri)' Now load the documentDim options As New LoadDocumentOptions()options.Cache = cacheUsing document As Leadtools.Document.LEADDocument = DocumentFactory.LoadFromUri(uploadUri, options)PrintOutDocumentInfo(document)End UsingEnd SubPublic Shared Sub PrintOutDocumentInfo(ByVal document As LEADDocument)Console.WriteLine("General")Console.WriteLine(" DocumentId:" + document.DocumentId)If Not IsNothing(document.Uri) ThenConsole.WriteLine(" Uri:" + document.Uri.ToString())ElseConsole.WriteLine(" Name:" + document.Name)End IfConsole.WriteLine(" CacheStatus:" + document.CacheStatus.ToString())Console.WriteLine(" LastCacheSyncTime:" + document.LastCacheSyncTime.ToString())Console.WriteLine(" IsReadOnly:" + document.IsReadOnly.ToString())Console.WriteLine(" IsLocal:" + document.IsLocal.ToString())Console.WriteLine(" MimeType:" + document.MimeType)Console.WriteLine(" IsEncrypted:" + document.IsEncrypted.ToString())Console.WriteLine(" IsDecrypted:" + document.IsDecrypted.ToString())If Not IsNothing(document.UserData) ThenConsole.WriteLine(" UserData:" + document.UserData.ToString())End IfConsole.WriteLine("Cache")Console.WriteLine(" HasCache:" + document.HasCache.ToString())Console.WriteLine(" AutoDeleteFromCache:" + document.AutoDeleteFromCache.ToString())Console.WriteLine("Metadata")For Each item As KeyValuePair(Of String, String) In document.MetadataConsole.WriteLine(" {0} {1}", item.Key, item.Value)NextConsole.WriteLine("Documents")Console.WriteLine(" Count:" + document.Documents.Count.ToString())For Each childDocument As LEADDocument In document.DocumentsConsole.WriteLine(" Name:" + childDocument.Name)NextConsole.WriteLine("Pages")Console.WriteLine(" Count:" + document.Pages.Count.ToString())For pageNumber As Integer = 1 To document.Pages.CountDim page As Leadtools.Document.DocumentPage = document.Pages(pageNumber - 1)Console.WriteLine(" PageNumber:" + pageNumber.ToString())Console.WriteLine(" OriginalPageNumber:" + page.OriginalPageNumber.ToString())Console.WriteLine(" OriginalDocumentName:" + page.Document.Name)Console.WriteLine(" Size:{0}", page.Size.ToString())NextConsole.WriteLine("--------")End SubPublic Shared Function GetCache() As ObjectCache' Create a LEADTOOLS FileCache objectDim cacheDir As String = Path.Combine(ImagesPath.Path, "cache")If Directory.Exists(cacheDir) ThenDirectory.Delete(cacheDir, True)End IfDirectory.CreateDirectory(cacheDir)Dim cache As New FileCache()cache.CacheDirectory = cacheDirReturn cacheEnd Function
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
