This content has been marked as final. Show 6 replies
If the getHeaders() method returns null, I expect that's because there are no headers. Checking the API documentation should confirm it -- I don't have it at hand right now but you should, so I will leave that for you to do.
Were you expecting a header which would identify the type of the file being uploaded? What do you mean by "file type" anyway?
Yes I was hoping I could grab the file header to determine the file type (i.e. png, txt, exe). The content-type property seems to be based off the file extension, which I can easily change. I wanted something a little more concrete... but maybe the header is not as concrete as I think it is.
I think the best you can do is to get the file name and extract the extension from it. Yes, people can rename files so that a Windows executable masquerades as a GIF image, but I really wouldn't expect the file upload process to be examining the contents of the upload and deciding what it really is. You would have to do that yourself if you really wanted that information.
How would I accomplish that? Is the file header not a good way to determine that?
I don't know what you mean by "the file header".
If you're referring to the "headers" returned by FileItem.getHeaders(), those are HTTP headers, aren't they? And they are whatever headers the client decided to put into the upload. I can't imagine clients which analyze the contents of the files they are uploading and insert a header to say "This file is a Windows executable" or anything like that. It seems to me you're reading the documentation in wish-fulfillment mode.
This is what I mean by file header http://en.wikipedia.org/wiki/File_format#File_header
Basically an alternate way of determining a file type other than the extension.