Page 1 of 1
Drag Images from external source to firefox
Posted: Wed Apr 25, 2007 11:51 pm
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
Posted: Thu Apr 26, 2007 1:51 pm
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.
Posted: Thu Apr 26, 2007 2:24 pm
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?
Posted: Thu Apr 26, 2007 2:27 pm
by Weirdan
Posted: Thu Apr 26, 2007 2:28 pm
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.
Posted: Thu Apr 26, 2007 3:15 pm
by Kieran Huggins
what's involved in signing a script anyway?
Posted: Thu Apr 26, 2007 3:46 pm
by aaronhall
Here's what I found:
http://www.mozilla.org/projects/securit ... ripts.html -- never knew about it till now.
Posted: Thu Apr 26, 2007 10:46 pm
by Todd_Z
feyd | Please use 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
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]
Posted: Fri Apr 27, 2007 9:47 am
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.
Posted: Fri Apr 27, 2007 11:46 am
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?
Posted: Fri Apr 27, 2007 6:33 pm
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?
Posted: Sun Apr 29, 2007 4:50 pm
by Todd_Z
It does, and it still gives that error.
Posted: Sun Apr 29, 2007 11:21 pm
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.