2

I want to test the following method (generated by swagger) with fiddler:

[HttpPost]
[Route("/webservice/images")]
[SwaggerOperation("UploadImage")]
[SwaggerResponse(200, type: typeof(ResourceIdEntry))]
public virtual IActionResult UploadImage([FromForm] Stream image)
{
    return new ObjectResult();
}

I configure Fiddler to send a POST to http://localhost:50352/webservice/images with the Header

Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
User-Agent: Fiddler
Host: localhost:50352
Content-Length: 12931

and the body

---------------------------acebdf13572468
Content-Disposition: form-data; name="image"; filename="Test.tif"
Content-Type: image/tiff

<@INCLUDE *C:\...\Test.tif*@>
---------------------------acebdf13572468--

but UploadImage is not even called and I just get a 500 returned. If I remove the image parameter, the Method gets at least called. How do I have to configure fiddler so that the call is resolved correctly?

Sebastian
  • 754
  • 4
  • 7
  • 20
  • I was facing similar problem with snapchat api. the root cause was the way they were parsing request body. the solution was to wrap name and filename with quotes, like: "name"="image";"filename"="Test.tif". Hope this helps – Artem Aug 14 '17 at 10:00
  • @Artem, nope, doesn't work for me. Thanks for trying. – Sebastian Aug 14 '17 at 10:22

1 Answers1

0

Checkout the following post around uploading file with web api - https://learn.microsoft.com/en-us/aspnet/web-api/overview/advanced/sending-html-form-data-part-2

There is no built in media formatter for dealing with multi part form posts. However this is nothing stopping you writing your own so the same logic can be applied to multiple actions, here is a gist example of a custom formatter - https://gist.github.com/Danielku15/bfc568a19b9e58fd9e80

Kevin Smith
  • 13,746
  • 4
  • 52
  • 77
  • Sorry, I'm not getting it. For the first link: It does make it clear to me, how to rewrite my Fiddler request and I'm already able to read the Files from Request.Form.Files, but I want to get them by a Parameter. Second link uses System.Web, is that transferable to asp.netcore? Also it seems be a lot of code in comparison to foreach file in Request.Form.Files {something}. Furthermore, I don't think I understand the problem why the parameter is not set. Please elaborate on this. – Sebastian Aug 14 '17 at 12:35
  • Regarding the second link I posted a follow-up question here: https://stackoverflow.com/questions/46296372/why-are-the-attributes-of-this-model-initialized-to-null – Sebastian Sep 19 '17 at 09:13