MIME type whitelisting support.
public static DocumentMimeTypes MimeTypes { get; }
public:
static property DocumentMimeTypes^ MimeTypes
{
DocumentMimeTypes^ get()
}
MimeTypes # get (DocumentFactory)
DocumentMimeTypes object to support MIME type whitelisting in this DocumentFactory.
For more information, refer to DocumentMimeTypes.
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");
}
}
}
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