PDA

View Full Version : multiple instance of file upload


perspolis
09-03-2007, 09:14 AM
Hi,

I am trying to create multiple instance of file upload but it is not working. for example I have two instance of file upload, I use the first instance and select a file. Then the data will be passed to second instance.

here is my sample code
<canvas>
<include href="fileupload.lzx"/>
<class name="mine>
<fileUpload name="myFileUpload">
<method name="onComplete" args="fr"><![CDATA[
canvas.progressBar.setValue(100);
canvas.upload.setAttribute('enabled', false);
]]>
</method>

<method name="onProgress" args="fr, bytesLoaded, bytesTotal"><![CDATA[
canvas.progressBar.setValue(bytesLoaded * 100 / bytesTotal);
]]>
</method>

<method name="onSelect" args="fr"><![CDATA[
canvas.txtFile.setText(getName());
canvas.upload.setAttribute('enabled', true);
]]>
</method>
</fileUpload>

<edittext x="10" y="10" width="200" name="txtFile" enabled="false"/>

<button x="210" y="11" text="Browse...">
<method event="onclick"><![CDATA[
myFileUpload.browse();
]]>
</method>
</button>

<button name="upload" x="290" y="11" text="Upload" enabled="false">
<method event="onclick"><![CDATA[
myFileUpload.upload('../myServlet'); // This should be the complete URL where we want to upload the file
]]>
</method>
</button>

<view name="progressBar" x="356" y="11" width="50" height="24" bgcolor="#666666">
<view x="1" y="1" width="48" height="22" bgcolor="#FFFFFF"/>
<view name="status" x="1" y="1" height="22" bgcolor="#BBBBFF"/>
<text name="percent" x="5" y="3" fontstyle="bold" fgcolor="#6666FF"/>

<method name="setValue" args="value"><![CDATA[
status.setAttribute('width', value * 48 / 100);
percent.setText(Math.round(value) + '%');
]]>
</method>
</view>
</class>

<simplelayout axis="y" spacing="10"/>
<mine/>
<mine/>
</canvas>


----------------

and the fileupload.lzx

<library>
<class name="fileUpload">
<method event="oninit" args="invoker"><![CDATA[
fr = new flash.net.FileReference();
fr.addListener(invoker);
]]>
</method>

<method name="browse"><![CDATA[
fr.browse();
]]>
</method>

<method name="getName"><![CDATA[
return fr.name;
]]>
</method>

<method name="upload" args="url"><![CDATA[
fr.upload(url);
]]>
</method>
</class>
</library>


thanks for your help

senshi
09-03-2007, 02:39 PM
Ok, that was just another example of doing copy and paste without actually knowing what's happening in the code... ;)

However, here's an updated version for fileupload, but I didn't perform any tests, so I cannot assure that this will work perfectly.

fileupload_test:

<canvas debug="true" >
<include href="fileupload.lzx"/>

<class name="uploadview" extends="view" >
<fileupload name="myFileUpload" >
<method name="onComplete" args="fr" ><![CDATA[
this.classroot.progressBar.setValue(100);
this.classroot.upload.setAttribute("enabled", false);
]]></method>

<method name="onProgress" args="fr, bytesLoaded, bytesTotal" ><![CDATA[
this.classroot.progressBar.setValue(bytesLoaded * 100 / bytesTotal);
]]></method>

<method name="onSelect" args="fr" ><![CDATA[
this.classroot.txtFile.setText(this.getName());
this.classroot.upload.setAttribute("enabled", true);
]]></method>
</fileupload>

<edittext x="10" y="10" width="200" name="txtFile" enabled="false" />

<button x="210" y="11" text="Browse..." >
<handler name="onclick"><![CDATA[
this.classroot.myFileUpload.browse();
]]></handler>
</button>

<button name="upload" x="290" y="11" text="Upload" enabled="false" >
<handler name="onclick"><![CDATA[
this.classroot.myFileUpload.upload("../myServlet");
]]></handler>
</button>

<view name="progressBar" x="356" y="11" width="50" height="24" bgcolor="#666666" >
<attribute name="prgwidth" value="48" type="number" />

<view x="1" y="1" width="$once{this.parent.prgwidth}" height="22" bgcolor="#FFFFFF" />
<view name="status" x="1" y="1" height="22" bgcolor="#BBBBFF" />
<text name="percent" x="5" y="3" fontstyle="bold" fgcolor="#6666FF" />

<method name="setValue" args="value" ><![CDATA[
this.status.setAttribute("width", value * this.prgwidth / 100);
this.percent.setText(Math.round(value) + "%");
]]></method>
</view>
</class>

<simplelayout axis="y" spacing="10" />

<uploadview />

<uploadview />

</canvas>


fileupload.lzx:

<library>
<class name="fileupload" extends="node" >
<attribute name="fr" value="null" />

<method name="init" ><![CDATA[
super.init.apply(this, arguments);
if ($swf8) {
#pragma "passThrough=true"
this.fr = new flash.net.FileReference();
this.fr.addListener(this);
} else {
if ($debug) {
Debug.warn("You need to compile for Flash8 to enable file-upload!");
}
}
]]></method>

<method name="browse"><![CDATA[
this.fr.browse();
]]></method>

<method name="getName"><![CDATA[
return this.fr.name;
]]></method>

<method name="upload" args="url"><![CDATA[
this.fr.upload(url);
]]></method>
</class>
</library>

perspolis
09-06-2007, 04:49 AM
thanks,

its working

mrquejo
09-06-2007, 10:58 AM
I was copied and pasted the source code of this file upload example, but when i click the browser button i got an error from fileupload.lzx at line 19 (this.fr.browse() ):
ERROR: fileupload.lzx,19: Call to undefined 'method 'browse'
It seems that the "init" method of fileupload.lzx doesnt working correctly. Maybe at that call :
this.fr = new flash.net.FileReference();
Whats happening? I need a FileUploader urgently.
Another thing is, this code works on flash player 9 ( Obviosly removing the swf8 condition at fileupload.lzx)?
Thanks for any Help, and sry for my poor english.:D

senshi
09-06-2007, 11:29 AM
Another thing is, this code works on flash player 9 ( Obviosly removing the swf8 condition at fileupload.lzx)?

You must compile to SWF8, therefore I've added the compile-time condition "if ($swf8)". However, this is not related to the actual FlashPlayer you are using, but only to the Runtime-Target.

alyjeje
04-16-2008, 02:28 AM
Hi !! I'm using these files and that work, thanks senshi ; )
But in my program I want to get a file.log (a xml file ) in order to parse it !
Now I use en edittext when you write the path of the file and I import create a dataset.
How can I get the path of my file that I've just upload ?
thanks for your replies

alyjeje
04-16-2008, 10:54 PM
up please .....