3

Hello i need a DnD Solution to Drag Outlook Mail Attachments to a Stackpane.

JavaFX / Outlook 2010

    stackpaneDragAndDropZone.setOnDragOver((DragEvent event) -> {
        Dragboard db = event.getDragboard();
        System.out.println(db.getContentTypes());
    });

Has this Output:

[[message/external-body;access-type=clipboard;index=0;name="faxdoc-150217-1300-+49-206581978.pdf"], [RenPrivateItem]]

How can i use this RenPrivateItem?

On regular Java i got a file with this code:

    dropTarget.addDropTargetListener(new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde) {
            Transferable t = dtde.getTransferable();

            try {
                DataFlavor[] dataFlavors = t.getTransferDataFlavors();

                dtde.acceptDrop(DnDConstants.ACTION_COPY);

                //create a temp file
                File temp = File.createTempFile("temp-file-name", ".tmp");

                for (int i = 0; i < dataFlavors.length; i++) {
                    File file = new File(t.getTransferData(dataFlavors[i]).toString().replace("[", "").replace("]", ""));
                    Desktop.getDesktop().open(new File(file.getCanonicalPath()));
                }

                dtde.dropComplete(true);

            } catch (Exception ex) {

                ex.printStackTrace();

            }

        }

    });
reiga
  • 31
  • 2

2 Answers2

0

It is a private format as the name suggests. But you will get CF_FILEDESCRIPTOR and CF_FILECONTENTS formats.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • thanks, nevertheless i search for a solution to get the path of the attachment in my javafx application. – reiga Feb 20 '15 at 07:16
  • "path of the attachment"? Are you not the one who adds the attachment to begin with? – Dmitry Streblechenko Feb 20 '15 at 17:10
  • i have a mail with the attachment and drag and drop the attachment from outlook to my javafx application. how i get the attachment file? this is my problem. i get only this: [[message/external-body;access-type=clipboard;index=0;name="faxdoc-1502 17-1300-+49-206581978.pdf"], [RenPrivateItem]] and have no idea how i can use this on javafx!? – reiga Feb 22 '15 at 07:15
  • See http://stackoverflow.com/questions/17184369/upload-fails-when-user-drags-and-drops-attachement-from-email-client/17197224#17197224 – Dmitry Streblechenko Feb 22 '15 at 17:03
  • I don't know, sorry - I do not use Java. – Dmitry Streblechenko Feb 23 '15 at 14:19
0

Edit: This only works for the system clipboard. Still unable to get the dragboard to work with outlook attachments.

You can take a look at this answer: https://stackoverflow.com/a/73166666/4489577

Essentially if you know you have something with message/external-body;access-type=clipboard, you can use:

DataFormat df = DataFormat.lookupMimeType("message/external-body");
if (df == null) {
  df = new DataFormat("message/external-body");
}
Object inMemoryFile = clipboard.getContent(df);

to access it. Using the full mime type gives null when you use getContent().

Then you can just cast it to ByteBuffer and do whatever you want with the file's bytes.

Dean Wookey
  • 181
  • 2
  • 4
  • `pane.setOnDragOver((DragEvent event) -> { event.getDragboard().getContent(DataFormat.lookupMimeType("message/external-body")); System.exit(0); });` never quits the app... or in other words, it never gets to the second line... – trilogy Jul 29 '22 at 20:00
  • Can you show a full working example? It doesn't seem to be working. – trilogy Jul 29 '22 at 20:01
  • Sorry, I only tested the system clipboard. I'm still trying to get to the bottom of why the dragboard doesn't work. – Dean Wookey Aug 02 '22 at 08:52
  • I tried with the system clipboard and it’s also the same issue … – trilogy Aug 02 '22 at 10:11