FileFormatUtil.detectFileFormat always returns 255

I have a web page that allows users to upload a file. It is running inside of a J2EE web server (Websphere Application Server). Our company has bought a Total License. We are wanting to use Aspose to make sure that the files do not have any malware. I am trying to get the file format and extension using the detectFileFormat method of the FileFormatUtil class.

javax.servlet.http.Part file; //+getter and setter

FileFormatInfo formatInfo = FileFormatUtil.detectFileFormat(file.getInputStream());

I am selecting a word document (.docx) to upload. The method always returns 255 which I believe is an unknown document type. I have also tried a text document (.txt) which also returns 255, unknown document type.

We need to be able to verify that the document is safe before we allow the file to be uploaded.

Thanks in advance.

@dougcherold,

I have observed the issue shared by you and request you to please share the source files that you have used to verify the issue on your end.

@dougcherold,

Thanks for your inquiry. If you are facing this issue with all documents, the issue might be in your Java code. Please make sure that you are uploading the correct file and javax.servlet.http.Part.getInputStream() is returning the correct document stream. Please save this stream to disk using Java code and check if it is valid DOCX and TXT.

If you still face problem, please attach the following resources here for testing:

  • Your input Word document and TXT document.
  • Please share source code without compilation errors that helps us to reproduce your problem on our end.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

I think the problem was with the license. I restarted my server several times and that did not fix the problem.

I hard coded the path to the Aspose.Total.Java.lic file and then rebooted the whole computer. This seemed to fix my issue. Thank you so much for your prompt response.