Home > front end >  RestSharp upload image with imagesource. (Image exist only as Variable)
RestSharp upload image with imagesource. (Image exist only as Variable)

Time:08-17

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);

CodePudding user response:

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.

  • Related