creating a webservice that accepts a file (Stream) doesnt want other params

前端 未结 6 1476
梦毁少年i
梦毁少年i 2021-01-13 22:50

I have a File i want to upload to a Webservice, but it needs additional params, so I create some hidden fields with the associated name:value pairs to get pushed to the serv

6条回答
  •  粉色の甜心
    2021-01-13 23:10

    How about using HttpRequest.QueryString[]?

    [OperationContract]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "NewImage")]
    string NewImage(Stream data);
    

    you call it through the URL like:

    \NewImage?server={server}&datasource={datasource}&document={doc}&image_id={id}
    

    Then in your code:

    public string NewImage(Stream imgStream)
    {
        var request = System.Web.HttpContext.Current.Request;
    
        var server= request.QueryString["server"];
        var datasource = request.QueryString["datasource"];
        var document= request.QueryString["document"];
        var image_id= request.QueryString["image_id"];
    
        ...
    }
    

    I'd been looking for something like this for a while, and just stumbled across it today.

提交回复
热议问题