title: RestSharp AddFile using key and image in C#
body: <p>I´m trying to consume a Rest service that receives an image with a key. I am using RestSharp v.106.10.1 in Visual Studio 2017. I have the following code, which when executing returns a message with the server response that says the package has arrived without the image. Can you help me on what am I doing wrong?.</p>
  
  <p>This is my code</p>
  
  <pre><code>var client = new RestClient("http://localhost:3030/api/upload-image");
      client.Timeout = -1;
      var request = new RestRequest(Method.POST);
      request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
      request.AddFile("images", "/C:/Users/Desktop/AppTestWM/ServidorFTP/450_1000.jpg");
      IRestResponse response = client.Execute(request);
      Console.WriteLine(response.Content);
  </code></pre>
  
  <p>The way to send from postman is this. the header contentType: application/x-www-form-urlencoded  and the body in form-data added a key “image” and the image file.</p>
  
  <p>This is header format</p>
  
  <p><a href="https://i.stack.imgur.com/EivDN.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>This is body format</p>
  
  <p><a href="https://i.stack.imgur.com/curgj.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>MORE IINFORMATION</p>
  
  <p>This is postman console good answer</p>
  
  <p>POST <a href="http://localhost:3000/imagenSoliTag/upload-image" rel="nofollow noreferrer">http://localhost:3000/imagenSoliTag/upload-image</a></p>
  
  <p>• ▶Network</p>
  
  <p>▶Request Headers</p>
  
  <p>User-Agent: PostmanRuntime/7.24.1</p>
  
  <p>Accept: /</p>
  
  <p>Cache-Control: no-cache</p>
  
  <p>Postman-Token: 44761995-f969-417d-9216-c98d2ee38b35</p>
  
  <p>Host: localhost:3000</p>
  
  <p>Accept-Encoding: gzip, deflate, br</p>
  
  <p>Connection: keep-alive</p>
  
  <p>Content-Type: multipart/form-data; boundary=------------------------- -505415277809498326289672</p>
  
  <p>Content-Length: 20233</p>
  
  <p>• ▶Request Body</p>
  
  <p>▶image: {…}</p>
  
  <p>_events: {}</p>
  
  <p>_eventsCount: 3</p>
  
  <p>▶_readableState: {…}</p>
  
  <p>autoClose: true</p>
  
  <p>bytesRead: 20022</p>
  
  <p>closed: true</p>
  
  <p>domain: null</p>
  
  <p>fd: null</p>
  
  <p>flags: "r"</p>
  
  <p>mode: 438</p>
  
  <p>path: "C:\Users\Desktop\AppTestWM\ServidorFTP\450_1000.jpg"</p>
  
  <p>readable: false</p>
  
  <p>▶Response Headers</p>
  
  <p>X-Powered-By: Express</p>
  
  <p>Content-Type: application/json; charset=utf-8</p>
  
  <p>Content-Length: 71</p>
  
  <p>ETag: W/"47-DTIxeI6y0HsQCMVrZcYol72rDDs"</p>
  
  <p>Date: Sun, 19 Apr 2020 23:42:08 GMT</p>
  
  <p>Connection: keep-alive</p>
  
  <p>• ▶Response Body</p>
  
  <p>response: "¡Imagen guardada con éxito!"</p>
  
  <p>imagePath: "450_1000.jpg"</p>
  
  <p>This is postman console bad answer when make a query without image</p>
  
  <p>POST <a href="http://localhost:3000/imagenSoliTag/upload-image" rel="nofollow noreferrer">http://localhost:3000/imagenSoliTag/upload-image</a></p>
  
  <p>• ▶Network</p>
  
  <p>▶Request Headers</p>
  
  <p>User-Agent: PostmanRuntime/7.24.1</p>
  
  <p>Accept: /</p>
  
  <p>Cache-Control: no-cache</p>
  
  <p>Postman-Token: 9903417e-e3f0-467e-a185-046a1043ba45</p>
  
  <p>Host: localhost:3000</p>
  
  <p>Accept-Encoding: gzip, deflate, br</p>
  
  <p>Connection: keep-alive</p>
  
  <p>Content-Length: 0</p>
  
  <p>• Request Body</p>
  
  <p>▶Response Headers</p>
  
  <p>X-Powered-By: Express</p>
  
  <p>Content-Type: application/json; charset=utf-8</p>
  
  <p>Content-Length: 50</p>
  
  <p>ETag: W/"32-Z/sIWz99etyVziu3PXRpXUZOG6c"</p>
  
  <p>Date: Sun, 19 Apr 2020 23:44:07 GMT</p>
  
  <p>Connection: keep-alive</p>
  
  <p>• ▶Response Body</p>
  
  <p>statusCode: 400</p>
  
  <p>message: "¡Elija una imagen!"</p>
  
  <p>This is Visual studio debug in Request</p>
  
  <p><a href="https://i.stack.imgur.com/iHEv3.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>and in Response debug is this</p>
  
  <p><a href="https://i.stack.imgur.com/AZsD3.png" rel="nofollow noreferrer">enter image description here</a></p>