Source of a MIME type callback invocation.
[SerializableAttribute()]
[DataContractAttribute()]
public enum DocumentMimeTypeSource
public:
[SerializableAttribute,
DataContractAttribute]
enum class DocumentMimeTypeSource sealed
class DocumentMimeTypeSource(Enum):
User = 0
Cache = 1
Url = 2
Data = 3
Value | Member | Description |
---|---|---|
0 | User | The mime type is passed by the user. For instance, in LoadDocumentOptions.MimeType. |
1 | Cache | The mime type is stored in the cache, for example, from BeginUploadDocumentOptions.MimeType. |
2 | Url | The mime type was obtained from the HTTP headers of a URL as set by the server containing the document. |
3 | Data | The mime type is read by LEADTOOLS RasterCodecs from the actual image data. |
Refer to DocumentMimeTypes for more information.
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