Flex与.NET互操作(十五):使用FluorineFx中的字节数组(ByteArray)实现图片上传
前几天一位朋友问我一个问题,他说:“我用HTTP接口或是WebService接口可以实现图片上传功能,那么用FluorineFx如何实现图片上传功能呢?”,其实仔细看官方文档和示例程序的自己都可以找到答案,实现上传可以有很多种实现,这里我以官方所提供是示例为基础稍加改动,通过ByteArray类实现图片上传。首先建立FluorineFx库和网站,在远程服务器类里添加一个处理文件上传的方法,详细代码如下:
<div class="cnblogs_code"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->namespaceByteStream.Services
{
publicclassByteStreamService
{
publicByteArrayUploadImage(ByteArrayba)
{
MemoryStreamms=newMemoryStream(ba.GetBuffer());
Imageimg=Bitmap.FromStream(ms);
BitmapnewImage=newBitmap(img);
MemoryStreamtempStream=newMemoryStream();
newImage.Save(tempStream,System.Drawing.Imaging.ImageFormat.Png);
stringpath=HttpContext.Current.Server.MapPath("UpLoad/ByteArray.png");
FileStreamfs=newFileStream(path,FileMode.Create);
tempStream.WriteTo(fs);
fs.Close();
ByteArrayresult=newByteArray(tempStream);
returnresult;
}
}
}
页:
[1]