←Select platform

MimeType Property

Summary

MIME type of the document being uploaded.

Syntax
C#
C++/CLI
Python
public string MimeType { get; set; } 
public:  
   property String^ MimeType 
   { 
      String^ get() 
      void set(String^ value) 
   } 
MimeType # get and set (UploadDocumentOptions) 

Property Value

The MIME type of the document being uploaded if known. The default value is null.

Remarks

This value is optional and setting it depends on the application's requirement.

It is recommended to provide the value of MimeType while uploading the document. This will ensure that MIME type whitelisting is performed prior to reading any document data. Refer to DocumentFactory.MimeTypes for more information.

This value is just a hint for the factory when it first tries to load the document. If the value of MimeType is null or a wrong value, then it will be overridden by the factory and the real mime type obtained from the document data is set in LEADDocument.MimeType.

Note that the original value set here in MimeType will be returned by DocumentFactory.GetDocumentCacheInfo if called prior to the factory loading the document.

Example
C#
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; 
      do 
      { 
         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); 
   DocumentFactory.AbortUploadDocument(uploadUri); 
 
   // Now load the document 
   var options = new LoadDocumentOptions(); 
   options.Cache = cache; 
   using (var document = DocumentFactory.LoadFromUri(uploadUri, options)) 
   { 
      PrintOutDocumentInfo(document); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

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.