Applet - Drag & Drop, and Upload files

Hi,

I wish to be able to drag a file from my hard disk onto an applet within the browser, and have the applet then upload that file to the web server (or rather, pass it to a PHP file - via HTTP).

How can I do this?

I imagine the applet would need to be signed, right?

When the user drags and drops a file onto a component, how can I detect this? And then, how can I read this file up to the server via HTTP?

Thanks.
LVL 25
InteractiveMindAsked:
Who is Participating?
 
hoomanvCommented:
nice approach for Multipart Form File Upload
http://forum.java.sun.com/thread.jspa?forumID=31&threadID=451245
0
 
hoomanvCommented:
> I imagine the applet would need to be signed, right?
YES

> how can I read this file up to the server via HTTP?
create a URLConnection
read your file
send a POST request to server with Content-Type = "multipart/form-data"
write the file to the outputStream of connection
0
 
hoomanvCommented:
do you want to handle the uploaded file at server side too ?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
InteractiveMindAuthor Commented:
> create a URLConnection
> read your file
> send a POST request to server with Content-Type = "multipart/form-data"
> write the file to the outputStream of connection

I'm kinda new to applets... could I get a quick example please?


> do you want to handle the uploaded file at server side too ?
Using a PHP script, I intend to, yes... unless there's an easier way?
0
 
InteractiveMindAuthor Commented:
Wicked.
BTW, what's the ' ****4353 ' stuff all about?
0
 
colr__Commented:
The applet will require signing, yes.

Drag and drop is tricky to get working, but you can find info on it here: http://java.sun.com/docs/books/tutorial/dnd/index.html

For info on applets, see this link: http://java.sun.com/docs/books/tutorial/deployment/applet/

There is very little difference between an applet and an application, just some things youll have to remember - the lifecycle is different, restricted resourcse access for security ...

colr__
0
 
InteractiveMindAuthor Commented:
Yer, I've got the drag and drop thing working now.
Will have a play with implementing that multipart upload stuff.

Cheers.
0
 
hoomanvCommented:
> BTW, what's the ' ****4353 ' stuff all about?

it is called boundary. it distinguishes different parts of request

could be more helpful

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=23&t=002430
0
 
Mayank SAssociate Director - Product EngineeringCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.