简体   繁体   English

使用ASP.NET WebAPI v2,如何在WebAPI方法中POST PDF数据?

[英]Using ASP.NET WebAPI v2, how do I POST PDF data in a WebAPI method?

The idea is that there will be an external entity (SharePoint) that will call my WebAPI and pass in a PDF file as well as some extra, metadata information about that PDF file. 我们的想法是,将有一个外部实体(SharePoint)将调用我的WebAPI并传入PDF文件以及有关该PDF文件的一些额外的元数据信息。 I'm stuck on how to construct the signature of the Web API method. 我坚持如何构建Web API方法的签名。 Here's what I have so far: 这是我到目前为止所拥有的:

public class IssueController : ApiController
{
    private TestEntities db = new TestEntities(HelperClasses.ConnectionStringHelper.GetConnectionString());

    [HttpPost]
    public HttpResponseMessage SavePdf(Article a)
    {
        // save the PDF to a file share & metadata to the SQL database
    }
}

My inclination would be to do something like: 我倾向于做类似的事情:

public class IssueController : ApiController
{
    private TestEntities db = new TestEntities(HelperClasses.ConnectionStringHelper.GetConnectionString());

    [HttpPost]
    public HttpResponseMessage SavePdf(Article a, HttpPostedFileBase file)
    {
        // save the PDF to a file share & metadata to the SQL database
    }
}

But, I'm not sure with WebAPI how to exactly do this. 但是,我不确定WebAPI如何做到这一点。

QUESTION : How would I define a WebAPI method capable of accepting PDF data & some extra metadata as a POST request from an external entity? 问题 :如何定义一个能够接受PDF数据的WebAPI方法和一些额外的元数据作为来自外部实体的POST请求?

if you want to pass complex object , i suggest you to use JObject. 如果你想传递复杂的对象,我建议你使用JObject。

JObject: http://blog.travisgosselin.com/web-api-signatures-with-multiple-complex-parameters/ JObject: http ://blog.travisgosselin.com/web-api-signatures-with-multiple-complex-parameters/

PostFiles: http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2 PostFiles: http//www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM