File upload only handles .txt documents??
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I am using the following code to handle file uploads using JSP.
The form which calls this upload.jsp is of type multipart.
However the upload only works for txt documents, word douments .doc and .pdf documents do not open once uploaded to server. They say error opening file when trying to open.
Can someone help me with the following code, what do I need to do to handle binary uploads, I think at the minute it only supports ascii.
The whole upload process is handled by this upload.jsp file.
Some help please.
[ March 08, 2004: Message edited by: Annemarie McKeown ]
The form which calls this upload.jsp is of type multipart.
However the upload only works for txt documents, word douments .doc and .pdf documents do not open once uploaded to server. They say error opening file when trying to open.
Can someone help me with the following code, what do I need to do to handle binary uploads, I think at the minute it only supports ascii.
The whole upload process is handled by this upload.jsp file.
Some help please.
[ March 08, 2004: Message edited by: Annemarie McKeown ]
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Please use UBB code tags when posting code. Many people will not take the time to try and decipher unformatted blobs of code.
Annemarie McKeown
Ranch Hand
Posts: 47
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What are UBB code tags and how do I use them?
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
When you are at the page where you enter a topic or reply there are a bunch of buttons that will help enter UBB tags (similar to HTML markup, except using square brackets). There is also a link named "What is UBB Code?" that might be helpful.
Annemarie McKeown
Ranch Hand
Posts: 47
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thank you, can you please help me, ive been stuck at this problem for days.
Annemarie.
Annemarie.
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Without looking into it in any great detail, I'd take a look around your handling of "lines" and the '\r' character. Are you stripping these out? That makes no sense for binary files.
Is there a good reason that you are loathe to use one of the proven multi-part parsers and file uploaders such as the oreilly package and others that have been discussed in earlier topics?
Is there a good reason that you are loathe to use one of the proven multi-part parsers and file uploaders such as the oreilly package and others that have been discussed in earlier topics?
Annemarie McKeown
Ranch Hand
Posts: 47
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Yes, because I wanted to try it for myself and also because I couldn't get the o'reilly package working.
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I can certainly respect the "try it myself" reasoning, but if this is something you are under a deadline for, you might have had better luck trying to get help getting oreilly to work.
That said, I still believe that your primary problem is that you seem to be treating the file content as text-oriented; e.g. lines terminated with a \r. You should just treat the file content as 'blocks of bytes" with no interpretation. That way, the interpretation, be it text or binary, is preserved.
That said, I still believe that your primary problem is that you seem to be treating the file content as text-oriented; e.g. lines terminated with a \r. You should just treat the file content as 'blocks of bytes" with no interpretation. That way, the interpretation, be it text or binary, is preserved.
Annemarie McKeown
Ranch Hand
Posts: 47
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
thanks thats a big help.
Do you think I should use MultipartRequest as defined in the O'Reilly package?
Do you have any code for methods which handles with file uploads rather than reading it in by lines.
Annemarie
Do you think I should use MultipartRequest as defined in the O'Reilly package?
Do you have any code for methods which handles with file uploads rather than reading it in by lines.
Annemarie
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I am not sure whether pure JSP has such coding.
But I have worked with upload using Struts. We can define a Form which captures the upload parameters (defined in the Struts config file), then we need to define an ActionDispatcher to handle the request. When the container calls the ActionDispatcher's method, the files and the form parameters have already been uploaded to the Struct Form, and we can get all info, including the upload file, from the Form.
Before using Struts, I have also used JSP Smart upload, which is a free API for JSP to upload file. However, it has a serious security issue, and finally, this API is not recommended.
Nick.
But I have worked with upload using Struts. We can define a Form which captures the upload parameters (defined in the Struts config file), then we need to define an ActionDispatcher to handle the request. When the container calls the ActionDispatcher's method, the files and the form parameters have already been uploaded to the Struct Form, and we can get all info, including the upload file, from the Form.
Before using Struts, I have also used JSP Smart upload, which is a free API for JSP to upload file. However, it has a serious security issue, and finally, this API is not recommended.
Nick.
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Your problem (or at least one of them, I've not done exhaustive research) is that you're using a StringWriter to write out the uploaded data.
I think if you use some other mechanism (maybe a ByteArrayOutputStream) you should be able to write your data as binary without it getting corrupted.
The JavaDoc confirms this:
in fact, all Writers work on character arrays only and can cause corruption in binary data.
I think if you use some other mechanism (maybe a ByteArrayOutputStream) you should be able to write your data as binary without it getting corrupted.
The JavaDoc confirms this:
FileOutputStream is meant for writing streams of raw bytes such as image data. For writing streams of characters, consider using FileWriter.
in fact, all Writers work on character arrays only and can cause corruption in binary data.
42
| grapes are vegan food pellets. Eat this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |













