0

How to upload a Image with RestSharp without using a local path.

Image exists only in a Image Variable.

All i found was with a string as path, but this is not the way i want to go. Or is it possible to get the string Path from a ImageSource? How can this be solved?

My current code:

var client = new RestClient();
var request = new RestRequest(PostImageUrl, Method.Post);
request.AddOrUpdateHeader("Content-Type", "multipart/form-data");
request.AddFile("image", bauzeichnung);
request.AlwaysMultipartFormData = true;
var response = client.Execute(request);
Seth Macis
  • 115
  • 1
  • 10
  • Take a look at this https://stackoverflow.com/questions/15067894/c-sharp-restsharp-put-method-and-send-raw-bytes-protobuf just transform your image into an byte array. – Christian O. Aug 15 '22 at 12:09

1 Answers1

0

It is not possible, every file is need a source. But I can suggest methods that I do not recommend.

  1. You can convert image to base64 string and save image as string
  2. You can take Url of image and show in your app. But in this case image is should be updated to network before(Url).
  3. You can ConvertImage to base64 and store it in your cache.
  4. You can convert Image to ByteArray.

None of these recommendations are correct methods!!!

The most accurate method;

You can take the image and store it in your machine(Local or Server). Then tahe the path of image and save database as Url(If you don't know the difference between url and path, you should research it). When you send image just send the url of your image.

Mcan_Cicek
  • 234
  • 2
  • 7
  • sure i understand, but my main problem is that i cant send images with local paths. I dont know why but i already opened a thread where i explained my issue. maybe you can give a look on int. https://stackoverflow.com/questions/73359419/restsharp-content-type-is-not-changing?noredirect=1#comment129553055_73359419 .. thats the reason why i try something other instead of Path sending. – Seth Macis Aug 15 '22 at 12:30
  • i ansver it, but i think you should change your algorithm, this is not a good way for posting an image, also if you post the path, other devices or servers cant reach the image becouse path is private, you should work with url. – Mcan_Cicek Aug 15 '22 at 12:43