从上传的Flex文件WCF REST流的问题(如何解码在REST WS多部分表单提交) [英] Uploading file from Flex to WCF REST Stream issues (how to decode multipart form post in REST WS)

查看:512
本文介绍了从上传的Flex文件WCF REST流的问题(如何解码在REST WS多部分表单提交)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该系统是一个Flex应用程序与WCF REST Web服务通信。我试图从上传的Flex应用程序服务器的文件和正在运行到一些问题,我希望有人在这里将能够帮忙的。
我使用的FileReference的Flex应用程序浏览和上传文件的定义如下:

The system is a Flex application communicating with a WCF REST web service. I am trying to upload a file from the Flex application to the server and am running into some issues I'm hoping someone here will be able to help out with. I'm using a FileReference in the Flex app to browse and upload the file as defined here:

http://blog.flexexamples.com/2007/09/21/uploading -files-在使用Flex-最的FileReference类/

我再接收文件作为流(显示为System.ServiceModel。 Dispatcher.StreamFormatter.MessageBodyStream在调试器)在WCF REST Web服务(使用项目类型WCF 4 REST服务)

I am then receiving the file as a Stream (shows as System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream in the debugger) in the WCF REST web service (using project type of WCF 4 REST Service)

[WebInvoke(Method = "POST", UriTemplate = "_test/upload")]
public void UploadImage(Stream data)
{
    // TODO: just hardcode filename for now
    var filepath = HttpContext.Current.Server.MapPath(@"~\_test\testfile.txt");
    using (Stream file = File.OpenWrite(filepath))
    {
        CopyStream(data, file);
    }
}
private static void CopyStream(Stream input, Stream output)
{
    var buffer = new byte[8 * 1024];
    int len;
    while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
    {
        output.Write(buffer, 0, len);
    }
}

请注意:从这篇文章中使用CopyStream方法:<一HREF =htt​​p://stackoverflow.com/questions/411592/how-do-i-save-a-stream-to-a-file>如何流保存到一个文件?

Note: CopyStream method used from this post: How do I save a stream to a file?

该文件保存没有任何问题。我的问题是,该文件包含的比我想的信息。这里有保存文件的内容(源文件只包含这是文件的内容):

The file saves without any issues. The issue I have is that the file contains more information than i would like. Here are the contents of the saved file (where the source file only contained "THIS IS THE CONTENT OF THE FILE"):

------------ae0ae0Ef1ae0Ef1ae0gL6gL6Ij5cH2
Content-Disposition: form-data; name="Filename"

testfile.txt
------------ae0ae0Ef1ae0Ef1ae0gL6gL6Ij5cH2
Content-Disposition: form-data; name="Filedata"; filename="testfile.txt"
Content-Type: application/octet-stream

THIS IS THE CONTENT OF THE FILE
------------ae0ae0Ef1ae0Ef1ae0gL6gL6Ij5cH2
Content-Disposition: form-data; name="Upload"

Submit Query
------------ae0ae0Ef1ae0Ef1ae0gL6gL6Ij5cH2--

的内容看起来就像它们在的Adobe文档中描述:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html

The contents look exactly like they are described in the Adobe documentation: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html

有没有在C#中的任何设施,以从流中获取该文件的内容?

Are there any facilities in C# to get the file contents from the Stream?

修改(3/24下午八时15分):什么Flex应用程序发送一个多部分表单POST。由流参数来表示,并带出了多域主体的件多域主体的数据我怎么能解码?

EDIT (3/24 8:15 pm): What the Flex app is sending is a Multipart form POST. How can I decode the multipart body data as represented by the Stream parameter and strip out the pieces of the multipart body?

修改(3/25上午10点) :这是相关的一些堆栈溢出职位:结果
WCF服务接受一个职位编码的multipart / form-data的结果
发布的multipart / form-data的一个WCF REST服务:行动改变

EDIT (3/25 10 am): some more Stack Overflow posts that are related:
WCF service to accept a post encoded multipart/form-data
POSTing multipart/form-data to a WCF REST service: the action changes

修改(3/25上午10时45分):发现一个多解析器,工作得非常好:结果
http://antscode.blogspot.com/2009/11/parsing-multipart-form -data-在wcf.html提前

EDIT (3/25 10:45 am): Found a multipart parser that works very well:
http://antscode.blogspot.com/2009/11/parsing-multipart-form-data-in-wcf.html

感谢。

推荐答案

由于安东尼在上 http://antscode.blogspot.com/ 为分段解析器的伟大工程(对于图片,TXT文件等)。

Thanks to Anthony over at http://antscode.blogspot.com/ for the multipart parser that works great (for images, txt files, etc).

HTTP ://antscode.blogspot.com/2009/11/parsing-multipart-form-data-in-wcf.html

这篇关于从上传的Flex文件WCF REST流的问题(如何解码在REST WS多部分表单提交)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆