Laszlo上传文件Demo
简介:
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
<library>
<class name="fileUpload">
<method event="oninit" args="invoker">
<![CDATA[
Security.allowDomain("*");
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>

HelloWorld.lzx
<canvas>
<include href="fileupload.lzx"/>

<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="180" name="txtFile" enabled="false"/>

<button x="190" y="11" text="浏览文件
">
<method event="onclick">
<![CDATA[
myFileUpload.browse();
]]>
</method>
</button>

<button name="upload" x="270" y="11" text="上传" enabled="false">
<method event="onclick">
<![CDATA[
myFileUpload.upload('http://localhost/JZService/WebForm1.aspx');//使用你自己的上传处理地址
]]>
</method>
</button>

<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"/>

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

服务端代码: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);
}
}

}

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
<library>
<class name="fileUpload">
<method event="oninit" args="invoker">
<![CDATA[
Security.allowDomain("*");
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>
HelloWorld.lzx
<canvas>
<include href="fileupload.lzx"/>
<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="180" name="txtFile" enabled="false"/>
<button x="190" y="11" text="浏览文件
">
<method event="onclick">
<![CDATA[
myFileUpload.browse();
]]>
</method>
</button>
<button name="upload" x="270" y="11" text="上传" enabled="false">
<method event="onclick">
<![CDATA[
myFileUpload.upload('http://localhost/JZService/WebForm1.aspx');//使用你自己的上传处理地址
]]>
</method>
</button>
<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"/>
<method name="setValue" args="value">
<![CDATA[
status.setAttribute('width', value * 98 / 100);
percent.setText(Math.round(value) + '%');
]]>
</method>
</view>
</canvas>
服务端代码: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);
}
}
}


浙公网安备 33010602011771号