We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › drag n drop file upload applet
Page Index Toggle Pages: 1
drag n drop file upload applet (Read 5827 times)
drag n drop file upload applet
Jan 3rd, 2006, 11:21am
 

Hi guys,

Before I go barking up a wrong'un, would it be possible to implement a browser-based drag and drop file upload utility using processing

Here's an  example of one running in a browser:

http://www.radinks.com/upload/applet.php

any suggestions are appreciated.
Re: drag n drop file upload applet
Reply #1 - Jan 4th, 2006, 6:38pm
 
it could prolly work, though of course you'd need to sign the applet.. you may also need to use SwingUtilities.invokeLater() if you need to open a file chooser, but d&d should be ok. there's some d&d code in processing/app/Editor.java starting at line 240 which handles adding files to the sketch that could be used as a start. you may also want to use noLoop() and redraw() if it's not an animated thing.
Re: drag n drop file upload applet
Reply #2 - Jan 5th, 2006, 2:23pm
 
Thanks Ben.

What've you supplied gives me reason enough to try.

Re: drag n drop file upload applet
Reply #3 - Jul 12th, 2006, 5:53am
 
For those stumbling upon this thread and needing the solution real quick:

Quote:

import java.awt.dnd.*;
import java.awt.datatransfer.*;

DropTarget dt = new DropTarget(this, new DropTargetListener() {
 public void dragEnter(DropTargetDragEvent event) {
   // debug messages for diagnostics
   //System.out.println("dragEnter " + event);
   event.acceptDrag(DnDConstants.ACTION_COPY);
 }

 public void dragExit(DropTargetEvent event) {
   //System.out.println("dragExit " + event);
 }

 public void dragOver(DropTargetDragEvent event) {
   //System.out.println("dragOver " + event);
   event.acceptDrag(DnDConstants.ACTION_COPY);
 }

 public void dropActionChanged(DropTargetDragEvent event) {
   //System.out.println("dropActionChanged " + event);
 }

 public void drop(DropTargetDropEvent event) {
   //System.out.println("drop " + event);
   event.acceptDrop(DnDConstants.ACTION_COPY);

   Transferable transferable = event.getTransferable();
   DataFlavor flavors[] = transferable.getTransferDataFlavors();
   int successful = 0;

   for (int i = 0; i < flavors.length; i++) {
     try {
       Object stuff = transferable.getTransferData(flavors[i]);
       if (!(stuff instanceof java.util.List)) continue;
       java.util.List list = (java.util.List) stuff;

       for (int j = 0; j < list.size(); j++) {
         Object item = list.get(j);
         if (item instanceof File) {
           File file = (File) item;

         
           String filename = file.getPath();
           loadFile(filename);
         }
       }

     }
     catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
}
);




somewhere in the above, I call a function named loadFile(filename);
you will need that function somewhere else in your program, at which point you can hand off the system filepath to one of processing's built in file handlers.
This is not very robust (in fact it seems to cause problems as far reaching as the editor), but in might get you a little closer to a quick solution.
Re: drag n drop file upload applet
Reply #4 - Oct 6th, 2007, 9:48am
 
OMG ! i was just about to implement a filechooser when i stumbled about this. so freakin' easy. just c'n'p et voila !

i luv u guys !

-ray
Page Index Toggle Pages: 1