This seems a good way.

I tried this :

var f:File = new File( (e.data[0] as DroppedModel).fileData , (e.data[0] as DroppedModel).fileName ));
But the issue is to cast BinaryData to Array :(

Le 2023-07-11 19:30, Harbs a écrit :

You can also do this with the fileList:

for each (var file:File in fileList){
var ref:FileReference = new FileReference();
ref.fileReference = file;

var url:URLRequest = new URLRequest("http://myserver.com/upload_file.php";)
url.method = "POST";
ref.upload(url);
}

On Jul 11, 2023, at 7:46 PM, Harbs <harbs.li...@gmail.com> wrote:

Something like this?

private function dropped(ev:DragEvent):void{
ev.preventDefault();
var fileList:FileList = ev.dataTransfer.files;
dispatchEvent(new ValueEvent("filesAvailable",fileList));
}

The code from FileLoader is relevant for getting the binary content of a file:

public function load():void
{
COMPILE::SWF
{
fileModel.fileReference.addEventListener(Event.COMPLETE, fileLoadHandler);
fileModel.fileReference.load();
}
COMPILE::JS
{
var reader:FileReader = new FileReader();
goog.events.listen(reader, 'load', fileLoadHandler);
reader.readAsArrayBuffer(fileModel.fileReference);
}
}

COMPILE::SWF
protected function fileLoadHandler(event:flash.events.Event):void
{
fileModel.fileReference.removeEventListener(Event.COMPLETE, fileLoadHandler);
fileModel.fileContent = new BinaryData(fileModel.fileReference.data);
}

On Jul 11, 2023, at 7:26 PM, cont...@cristallium.com wrote:

Hi All,

I struggle with drag and drop and upload file to a remote server.

I can upload file using FileReference (_fr), this is working fine :

private function ev_SelectedFile(e:Event):void {
var url:URLRequest = new URLRequest("http://myserver.com/upload_file.php";)
url.method = "POST";
trace ("selected1:" + (e.currentTarget as FileReference).fileReference.name); trace ("selected2:" + (e.currentTarget as FileReference).fileReference.size); _fr.upload(url);
}

Now, instead to be _fr.browse(), I want the source of upload to be a drag and drop file. I have an event working using jewel DropZone when I drop a file, but how to setup FileReference ? Here is my buggy code :

private function ev_dropped(e:DroppedEvent):void {

trace ("dropped");
//_fr.fileReference = new File((e.data[0] as DroppedModel).fileData.array,"test.mp3");
_fr.fileContent = (e.data[0] as DroppedModel).fileData;
var url:URLRequest = new URLRequest("http://myserver.com/upload_file.php";)
url.method = "POST";
_fr.upload(url),
}

Thank in advance for help
Regards
Fred

--
Frédéric Gilli

mob.0668542622

http://www.cristallium.com

 [1]



Links:
------
[1] http://www.cristallium.com

Reply via email to