servicestack,multifile-uploader,Post,servicestack,Multifile Uploader" /> servicestack,multifile-uploader,Post,servicestack,Multifile Uploader" />

ServiceStack-使用一个POST请求发布多个文件

ServiceStack-使用一个POST请求发布多个文件,post,servicestack,multifile-uploader,Post,servicestack,Multifile Uploader,我为这个问题挣扎了几个小时,但我找不到任何解决办法。 是否有人使用ServiceStack通过一个POST请求上载多个文件 我试图使用PostFile: FileInfo fi = new FileInfo("ExampleData\\XmlAPI.xml"); var client = new XmlServiceClient("http://localhost:1337"); client.PostFile<DefaultResponse>("/test", fi,

我为这个问题挣扎了几个小时,但我找不到任何解决办法。 是否有人使用ServiceStack通过一个POST请求上载多个文件

我试图使用PostFile:

  FileInfo fi = new FileInfo("ExampleData\\XmlAPI.xml");
  var client = new XmlServiceClient("http://localhost:1337");
  client.PostFile<DefaultResponse>("/test", fi, "application/xml");
FileInfo-fi=newfileinfo(“ExampleData\\XmlAPI.xml”);
var client=新的XmlServiceClient(“http://localhost:1337");
client.PostFile(“/test”,fi,“application/xml”);
但在这里,我只能向请求中添加一个文件。
我的第二个尝试是使用LocalHttpWebRequestFilter,但其中只有一个扩展方法也允许只发布一个文件。

多个文件上载API允许您在一个HTTP请求中轻松上载多个流。它支持使用QueryString和 除了多个文件上载数据流之外,POST'ed FormData:

using (var stream1 = uploadFile1.OpenRead())
using (var stream2 = uploadFile2.OpenRead())
{
    var client = new JsonServiceClient(baseUrl);
    var response = client.PostFilesWithRequest<MultipleFileUploadResponse>(
        "/multi-fileuploads?CustomerId=123",
        new MultipleFileUpload { CustomerName = "Foo,Bar" },
        new[] {
            new UploadFile("upload1.png", stream1),
            new UploadFile("upload2.png", stream2),
        });
}

对旧问题/答案的新评论,但我发现它在
ServiceClientBase
中添加了扩展方法,以发布多个带有请求正文的文件。看起来像是作者手推的逻辑。@jklemmack thx的轻推:)更新了答案,包括在v4.0.54中添加的新的多文件上传API。哦,谷歌,你让我失望了!哭声咬牙切齿
using (var stream1 = uploadFile1.OpenRead())
using (var stream2 = uploadFile2.OpenRead())
{
    var client = new JsonHttpClient(baseUrl);
    var response = await client.PostFilesWithRequestAsync<MultipleFileUploadResponse>(
        new MultipleFileUpload { CustomerId = 123, CustomerName = "Foo,Bar" },
        new[] {
            new UploadFile("upload1.png", stream1),
            new UploadFile("upload2.png", stream2),
        });
}