Drag Images from external source to firefox

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Drag Images from external source to firefox

Post by Todd_Z »

I am looking for a solution to dragging images from anywhere - the internet, explorer, nautilus, whatever - into a <div> on my web page - at which point the image is uploaded.

Firefox extension would be the last resort - but the ones i have seen are simply for flickr or a service like that.

Thanks
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

OS drag and drop doesn't fire an event in the DOM tree - you'll have to use a firefox extension AT LEAST, if it's possible at all.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

I know that I can upload the images via a simple extension,

Is there a way that the extension can have a sidebar which watches a remote folder for new images, then they can be dragged and dropped into the window?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Kieran Huggins wrote:OS drag and drop doesn't fire an event in the DOM tree - you'll have to use a firefox extension AT LEAST, if it's possible at all.
You are wrong. All you need is a signed script.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

what's involved in signing a script anyway?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Here's what I found: http://www.mozilla.org/projects/securit ... ripts.html -- never knew about it till now.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


          pulling hair out of head         

[syntax="javascript"]
function dragDropHandler ( evt ) {

        evt.stopPropagation();

        try {

        netscape.security.PrivilegeManager.enablePrivilege( 'UniversalXPConnect' );
        netscape.security.PrivilegeManager.enablePrivilege( 'UniversalFileRead' );
        netscape.security.PrivilegeManager.enablePrivilege( 'UniversalFileWrite' );

        var dragService = Components.classes["@mozilla.org/widget/dragservice;1"].getService(Components.interfaces.nsIDragService);
        var dragSession = dragService.getCurrentSession();
        var transferObject = Components.classes["@mozilla.org/widget/transferable;1"].createInstance();
        transferObject = transferObject.QueryInterface( Components.interfaces.nsITransferable );

        transferObject.addDataFlavor("image/png");
        transferObject.addDataFlavor("image/jpg");
        transferObject.addDataFlavor("image/gif");
        transferObject.addDataFlavor("text/plain");

        for ( var i = 0; i < dragSession.numDropItems; i++) {

                dragSession.getData( transferObject, i );

                var dataObj = new Object();
                var dropSizeObj = new Object();
                var bestFlavor = new Object();

                transferObject.getAnyTransferData( bestFlavor, dataObj, dropSizeObj );

                alert( bestFlavor.value );

                var droppedFile = dataObj.value.QueryInterface( Components.interfaces.nsIFile );

                alert("dataObj filename is " + droppedFile.path + ", num is " + dropSizeObj.value);

        }

        } catch ( err ) { $('ad').innerHTML = err; }

}

window.addEventListener( "dragdrop", dragDropHandler, true );

[/syntax]

Code: Select all

[Exception... "Component returned failure code: 0x80004002 (NS_NOINTERFACE) [nsISupports.QueryInterface]" nsresult: "0x80004002 (NS_NOINTERFACE)" location: "JS frame :: http://127.0.0.1:8000/jsi/Edit_Advertisement.js :: dragDropHandler :: line 162" data: no]
line 162 is the line with the var droppedFiled....

Anyone have a nice pretty fix for this before i go bald?

Thanks all


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

From the tutorial I mentioned:
A couple of things about the Mozilla permissions system need to be pointed out right now, as they will affect how this drag and drop example is built:
  • Only a script on the local machine%u2019s file system or a signed script on a webpage can request that a privilege be enabled. If you attempt to call this method from an unsigned script, it will throw an exception. This does not matter for Part 1, but is the reason for Part 2 of this discussion
  • An enablePrivilege request has the same scope as a variable %u2013 if you are inside a method and request enablePrivilege, that privilege will go away when the method%u2019s execution ends. Also, requesting the permission in a <SCRIPT> block on page startup will *not* grant that permission for the whole page %u2013 it will go away with the </SCRIPT> tag that ends the block
files accessed via http even if they are at 127.0.0.1 are not considered to be on the local machine's file system.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

saw that, but if you change the field in about:config

Code: Select all

user_pref("signed.applets.codebase_principal_support", true);
shouldn't it act like it was a signed script?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Todd_Z wrote:shouldn't it act like it was a signed script?
Yes, it should ask user if he wants to grant the script extended privileges. Doesn't it do this?
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

It does, and it still gives that error.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Okay, so I have it working when the signed.applets.codebase_principal_support value is set to true. But now, I would need to set this value to true on the computers that access this page. Is it possible to have firefox ask the user whether the preference should be changed when I execute a command?

The page will be used for internal company purposes, so we can instruct the workers to allow this preference to be changed.
Post Reply