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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
hoomanvCommented:
do you want to handle the uploaded file at server side too ?
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?
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

InteractiveMindAuthor Commented:
Wicked.
BTW, what's the ' ****4353 ' stuff all about?
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__
InteractiveMindAuthor Commented:
Yer, I've got the drag and drop thing working now.
Will have a play with implementing that multipart upload stuff.

Cheers.
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
hoomanvCommented:
nice approach for Multipart Form File Upload
http://forum.java.sun.com/thread.jspa?forumID=31&threadID=451245

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.