与Htt的prequestMessage或流REST文件上传? [英] REST file upload with HttpRequestMessage or Stream?

查看:374
本文介绍了与Htt的prequestMessage或流REST文件上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是上传文件的REST客户端更好的办法?

What is the better way to upload a file for a REST client?

从WCF的Web API文档

From the WCF Web API Documentation

[WebInvoke(UriTemplate = "thumbnail", Method = "POST")]
public HttpResponseMessage UploadFile(HttpRequestMessage request)
{

从多个论坛的帖子:结果
<一href=\"http://stackoverflow.com/questions/7264503/wcf-rest-file-upload-with-additional-parameters\">WCF REST文件上传与其他参数

[WebGet(UriTemplate="", Method ="POST"]
public string UploadFile(Stream fileContents)

据我了解,第一种方法允许直接从后一个普通的HTML格式的文件。第二做法似乎更常见的所有论坛的帖子,我觉得。

I understand, that the first method allows to directly post a file from a normal HTML form. The 2nd approach seems more common on all forum posts I find.

什么,你会推荐,为什么?该REST API应该从各种语言和平台访问。

What would you recommend and why? The REST api should be accessible from all kind of languages and platforms.

有关的Htt的prequestMessage方法,我会怎么做上传的文件preferable与WCF HttpClient的?随着FormUrlEn codedMediaTypeFormatter)

For the HttpRequestMessage approach, how would I do an upload a file preferable with the WCF HttpClient? With the FormUrlEncodedMediaTypeFormatter)

推荐答案

第一种方法是更接近金属,并会更加灵活,因为你将被处理http请求和建立自己的响应。如果你需要做的就是接受来自客户端的数据流,第二个选项是从实现角度看简单得多(引擎盖下,它同样的工作,第一种方法是做)

The first method is "closer to the metal" and would be more flexible since you would be processing the http requests and building the responses yourself. If all you need to do is accept a stream from a client, the second option is much simpler from the implementation standpoint (under the hood, it does the same work that the first method is doing)

我没有你的最后一个问题的答案。

I don't have an answer for your last question.

这篇关于与Htt的prequestMessage或流REST文件上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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