You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by co...@cristallium.com on 2023/07/11 16:26:03 UTC

Question about DropZone and FileReference

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

Re: Question about DropZone and FileReference

Posted by co...@cristallium.com.
Thanks for your ultra quick reply, I'm not in my conford area with these 
data types that I have never used.

I tried the following, but readAsArrayBuffer want a Blob type and 
DropEvent is giving an array of DroppedModel with fileData property wich 
is a BinaryData

How do you cast BinaryData to Blob ?

private function ev_dropped(e:DroppedEvent):void {

                 trace ("dropped");
                 var reader:FileReader = new FileReader();
                 reader.addEventListener('load', fileLoadHandler);
                 reader.readAsArrayBuffer( (e.data as 
DroppedModel).fileData  );<= issue here
             }

Le 2023-07-11 18:46, Harbs a écrit :

> 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, contact@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

Re: Question about DropZone and FileReference

Posted by co...@cristallium.com.
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 <ha...@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, contact@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

Re: Question about DropZone and FileReference

Posted by Harbs <ha...@gmail.com>.
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 <ha...@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, contact@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
> 


Re: Question about DropZone and FileReference

Posted by Harbs <ha...@gmail.com>.
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, contact@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