This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes Upload Download File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Upload Download File" Watch "Upload Download File" New topic
Author

Upload Download File

Ramy Raslan
Greenhorn

Joined: Dec 03, 2008
Posts: 8
i uploaded this .txt file

StartText{{{{{}}}}}EndText

but it into a DB2 Blop then download it in OutputStream

find this file

-----------------------------311112870412835 Content-Disposition: form-data; name="file"; filename="New Text Document.txt" Content-Type: text/plain StartText{{{{{}}}}}EndText -----------------------------311112870412835 Content-Disposition: form-data; name="SUBMIT" UPLOAD -----------------------------311112870412835--

as you can see any edit to the response is written to the OutputStream
which destroy all .doc and .jpeg file
can any one help
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61458
    
  67

Not without seeing your file handling code.

It looks as if the header values are being written to the file for some reason.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ramy Raslan
Greenhorn

Joined: Dec 03, 2008
Posts: 8
Upload form


Upload servlet



Download servlet
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why are you parsing the multipart form yourself when there are already libraries out there for free that have already been written an battle tested?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ramy Raslan
Greenhorn

Joined: Dec 03, 2008
Posts: 8
thanks for your reply can i ask you for some names of this libraries
Ramy Raslan
Greenhorn

Joined: Dec 03, 2008
Posts: 8
it works it just needed to be but into anther array of bytes
using the start position and end position




[ December 14, 2008: Message edited by: Ray Man ]
[ December 14, 2008: Message edited by: Ray Man ]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Honestly, that's very horrible code. This smells like a ripoff from roseindia.net. Please ignore that site forever, it almost only shows bad code examples and introduces bad practies. It's maintained by amateurs with the only focus on advertisement incomes.

To handle file upload I highly recommend you the Apache Commons FileUpload API. Here it is: http://commons.apache.org/fileupload Especially read the 'User Guide' section how to use it. It's fairly easy. For trouble or just for tips/tricks consult the 'Frequently Asked Questions' section. It's simply great stuff; thoroughly tested in all known situations and highly reliable.
[ December 14, 2008: Message edited by: Bauke Scholtz ]
Ramy Raslan
Greenhorn

Joined: Dec 03, 2008
Posts: 8
yes i know that but sadly i work on rational 6
which is the worst IDE you can see and it give me hard times
in my DB connection which is DB2 v8.1 express
bottom line i was in too much trouble with the db2 driver import to import any other jar

but thanks any way for the heads up i will sure take it in
consideration in the future
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
RAD is fine. You must be doing the stuff wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Upload Download File