File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Upload attachment using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Upload attachment using Java" Watch "Upload attachment using Java" New topic
Author

Upload attachment using Java

ruba sampath
Greenhorn

Joined: Jun 17, 2011
Posts: 28
Hi,

I need coding for uploading document:

Attachment size : <2mb
Attachement format : pictures or pdf

Kindly please help me to resolve the issue

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Where's your code? What problems are you having with it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Upload how? HTTP, FTP, through email?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
ruba sampath
Greenhorn

Joined: Jun 17, 2011
Posts: 28
Upload from my local PC and to store the document or picture in the database.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Use a third part library like HttpClient to upload files to a web server.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Are you looking for client code which can upload data through some protocol (HTTP, FTP, etc) to a server? Or are you looking for server code which can receive HTTP uploads?
ruba sampath
Greenhorn

Joined: Jun 17, 2011
Posts: 28
Looking for client code which can upload data through some protocol (HTTP, FTP, etc) to a server
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Okay. Client-side code then. But the code you use will depend on the protocol required by the server. So you should find out what that is.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Paul's right. The way files are uploaded in HTTP and FTP is quite different, and for SMB (a.k.a. Windows file sharing), NFS or SCP it's again completely different.

For HTTP you'll first need a page that can handle the file upload; a servlet, JSP page, PHP page, ASP page, etc. The HttpClient library I mentioned can then handle the rest.
For FTP you can use Apache Commons Net or JvFTP.
For SMB you can use regular java.io.File if the rights allow it, or JCIFS otherwise.
For SCP you can use JSch.

Of course these aren't the only libraries to use, but they do seem to be the most commonly used.
ruba sampath
Greenhorn

Joined: Jun 17, 2011
Posts: 28
Yes Paul. I need to upload the pdf or picture through local PC to database..
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

You'll need a table with a BLOB / binary / varbinary column. You then use PreparedStatement to insert / update a record in that table; PreparedStatement has a few setBinaryStream and setBlob methods and a setBytes method you can use for that.
ruba sampath
Greenhorn

Joined: Jun 17, 2011
Posts: 28
Thank you

I have inserted the record in the DB. But before inserting i have to find the file size in JSP using javascript without using ActiveXObject. Please Send me the code ASAP.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

ruba sampath wrote:Please Send me the code ASAP.

We are NotACodeMill. And please EaseUp.
ruba sampath
Greenhorn

Joined: Jun 17, 2011
Posts: 28
Hi Rob,

You have understand wrongly. Send me the code in the sense "teach me how to proceed the concept"... I knoe code ranch is for beginners to learn.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

I don't think this information is available through JavaScript. It's quite limited in what it can and cannot do with the file system.
ruba sampath
Greenhorn

Joined: Jun 17, 2011
Posts: 28
Thanks Rob
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Upload attachment using Java
 
Similar Threads
Downloading Excel File
Facing problem while compiling Action Class
Visual puzzle
StarUML Sequence diagram Ref Frame
Column value is getting reset to zero automatically in Jtable