We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PdfFileInfo IsPdfFile() performance & proper usage

Good morning,

I am working with file uploads, and one of the attributes I need to check is if the uploaded file is a PDF or not, and if it is, does it have a password.

rather than simply checking the extension of the file, I was trying to do the following:

    try
    {
        PdfFileInfo pdfFileInfo = new PdfFileInfo(stream);
        result = pdfFileInfo.IsPdfFile;
    }
    catch (Exception ex)
    {


}

However, what I am encountering is that during testing, our QA engineer tried to upload a 10MB .mp4 video file, and we found that the process hung on the constructor of PdfFileInfo

I figured since the PdfFileInfo class has the IsPdfFile() function, that I could try to construct a PdfFileInfo class and check if it was recognized as a PDF, but I need it to be well performing.

I am fine with checking the file extension of the uploaded file, but I’d rather use something that actually inspects the stream, since I think that is going to be more accurate.

Thoughts?
Thanks in advance,
-Brian

@bpieslak,

Thanks for contacting support.

Can you please share source file along with sample project to reproduce issue so that we may further investigate to help you out.