←Select platform

MimeTypes Property

Summary

MIME type whitelisting support.

Syntax
C#
C++/CLI
Python
public static DocumentMimeTypes MimeTypes { get; } 
public:  
   static property DocumentMimeTypes^ MimeTypes 
   { 
      DocumentMimeTypes^ get() 
   } 
MimeTypes # get  (DocumentFactory) 

Property Value

DocumentMimeTypes object to support MIME type whitelisting in this DocumentFactory.

Remarks

For more information, refer to DocumentMimeTypes.

Example
C#
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 MimeTypesWhitelistExample() 
{ 
   // Documents to try and load 
   string[] urls = 
   { 
      "https://demo.leadtools.com/images/pdf/leadtools.pdf", 
      "https://demo.leadtools.com/images/tiff/ocr.tif", 
      "https://demo.leadtools.com/images/png/pngimage.png" 
    }; 
 
   // Setup a callback for logging 
   // DocumentMimeTypes & DocumentMimeTypes.UserGetDocumentStatusHandler reference 
   DocumentMimeTypes.UserGetDocumentStatusHandler userGetDocumentStatus = (Uri uri, LoadDocumentOptions options, DocumentMimeTypeSource source, string mimeType) => 
   { 
      // Use default operation 
      DocumentMimeTypeStatus status = DocumentFactory.MimeTypes.GetDocumentStatus(uri, options, source, mimeType); 
      string mimeTypeValue = mimeType != null ? mimeType : "[null]"; 
      DocumentFactory.MimeTypes.GetStatus(mimeTypeValue); 
      Console.WriteLine(string.Format("  ** Whitelist url:{0} source:{1} mimeType:{2} status:{3}", uri.ToString(), source, mimeTypeValue, status)); 
 
      return status; 
   }; 
 
   DocumentFactory.MimeTypes.UserGetDocumentStatus = userGetDocumentStatus; 
 
   // Load the documents, by default we should load all of them 
   Console.WriteLine("Everything should load OK"); 
   LoadDocuments(urls); 
 
   // Now, disable loading everything except PDF and TIFF and try again 
   Console.WriteLine("Disabling everything except PDF and TIFF"); 
   DocumentFactory.MimeTypes.DefaultStatus = DocumentMimeTypeStatus.Denied; 
   DocumentFactory.MimeTypes.Entries.Add("application/pdf", DocumentMimeTypeStatus.Allowed); 
   DocumentFactory.MimeTypes.Entries.Add("image/tiff", DocumentMimeTypeStatus.Allowed); 
   Console.WriteLine("Only PDF and TIFF should be loaeded"); 
   LoadDocuments(urls); 
 
   // Reset 
   DocumentFactory.MimeTypes.UserGetDocumentStatus = null; 
} 
 
private static void LoadDocuments(string[] urls) 
{ 
   var loadDocumentOptions = new LoadDocumentOptions(); 
 
   foreach (var url in urls) 
   { 
      Console.WriteLine(" Loading " + url); 
      using (var document = DocumentFactory.LoadFromUri(new Uri(url), loadDocumentOptions)) 
      { 
         if (document != null) 
            Console.WriteLine("  is Loaded"); 
         else 
            Console.WriteLine("  cannot be loaded"); 
      } 
   } 
} 
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.