Laszlo上传文件Demo
简介:
Flash8类库里提供了文件类,方便了上传/下载文件。下面的程序demo演示了LPS3.3.3生成flash来访问本地文件,在flash里上传用户选择的文件到服务器,flash客户端可以处理文件上传进度等多个事件,服务器端是C#写的文件接收模块,把用户上传的文件保存在服务器上。
测试效果:
![laszlo.JPG](/images/cnblogs_com/dannyr/laszlo.JPG)
注意:Url地址后一定要跟lzr=swf8,只有flash8以上的版本才支持文件上传,否则无效!
测试环境:
操作系统:windows2003 Server
JDK版本:JDK 5.0 Update 8
Tomcat版本:5.5.17
Laszlo版本:3.3.3
Flash版本: flash Player 9
WEB服务器:
IIS 6.0
.net FrameWork 1.1
客户端代码:
fileupload.lzx
<library>
<class name="fileUpload">
<method event="oninit" args="invoker">
<![CDATA[
Security.allowDomain("*");
fr = new flash.net.FileReference();
fr.addListener(invoker);
]]>
</method>
![](/Images/OutliningIndicators/None.gif)
<method name="browse">
<![CDATA[
fr.browse();
]]>
</method>
![](/Images/OutliningIndicators/None.gif)
<method name="getName">
<![CDATA[
return fr.name;
]]>
</method>
![](/Images/OutliningIndicators/None.gif)
<method name="upload" args="url">
<![CDATA[
fr.upload(url);
]]>
</method>
</class>
</library>
![](/Images/OutliningIndicators/None.gif)
HelloWorld.lzx
<canvas>
<include href="fileupload.lzx"/>
![](/Images/OutliningIndicators/None.gif)
<fileUpload name="myFileUpload">
<method name="onComplete" args="fr">
<![CDATA[
canvas.progressBar.setValue(100);
canvas.upload.setAttribute('enabled', false);
]]>
</method>
![](/Images/OutliningIndicators/None.gif)
<method name="onProgress" args="fr, bytesLoaded, bytesTotal">
<![CDATA[
canvas.progressBar.setValue(bytesLoaded * 100 / bytesTotal);
]]>
</method>
![](/Images/OutliningIndicators/None.gif)
<method name="onSelect" args="fr">
<![CDATA[
canvas.txtFile.setText(getName());
canvas.upload.setAttribute('enabled', true);
]]>
</method>
</fileUpload>
<edittext x="10" y="10" width="180" name="txtFile" enabled="false"/>
![](/Images/OutliningIndicators/None.gif)
<button x="190" y="11" text="浏览文件
">
<method event="onclick">
<![CDATA[
myFileUpload.browse();
]]>
</method>
</button>
![](/Images/OutliningIndicators/None.gif)
<button name="upload" x="270" y="11" text="上传" enabled="false">
<method event="onclick">
<![CDATA[
myFileUpload.upload('http://localhost/JZService/WebForm1.aspx');//使用你自己的上传处理地址
]]>
</method>
</button>
![](/Images/OutliningIndicators/None.gif)
<view name="progressBar" x="330" y="11" width="100" height="24" bgcolor="#666666">
<view x="1" y="1" width="98" 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"/>
![](/Images/OutliningIndicators/None.gif)
<method name="setValue" args="value">
<![CDATA[
status.setAttribute('width', value * 98 / 100);
percent.setText(Math.round(value) + '%');
]]>
</method>
</view>
</canvas>
![](/Images/OutliningIndicators/None.gif)
服务端代码:WebForm1.aspx
private void Page_Load(object sender, EventArgs e) {
// 在此处放置用户代码以初始化页面
HttpFileCollection uploadedFiles = Request.Files;
string Path = Server.MapPath("data");
for(int i = 0 ; i < uploadedFiles.Count ; i++) {
HttpPostedFile F = uploadedFiles[i];
if(uploadedFiles[i] != null && F.ContentLength > 0) {
string newName = F.FileName.Substring(F.FileName.LastIndexOf("\\") + 1);
F.SaveAs(Path + "/" + newName);
}
}
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
Flash8类库里提供了文件类,方便了上传/下载文件。下面的程序demo演示了LPS3.3.3生成flash来访问本地文件,在flash里上传用户选择的文件到服务器,flash客户端可以处理文件上传进度等多个事件,服务器端是C#写的文件接收模块,把用户上传的文件保存在服务器上。
测试效果:
注意:Url地址后一定要跟lzr=swf8,只有flash8以上的版本才支持文件上传,否则无效!
测试环境:
操作系统:windows2003 Server
JDK版本:JDK 5.0 Update 8
Tomcat版本:5.5.17
Laszlo版本:3.3.3
Flash版本: flash Player 9
WEB服务器:
IIS 6.0
.net FrameWork 1.1
客户端代码:
fileupload.lzx
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
HelloWorld.lzx
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
服务端代码:WebForm1.aspx
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)