Answer the question
In order to leave comments, you need to log in
How to upload a photo using C#?
I use .NET Core, RestSharp
static Task<IRestResponse> GetResponseContentAsync(RestClient theClient, RestRequest theRequest)
{
var tcs = new TaskCompletionSource<IRestResponse>();
theClient.ExecuteAsync(theRequest, response => {
tcs.SetResult(response);
});
return tcs.Task;
}
async Task<ResponseWallUploadFile> GetWallUploadFile(string url, byte[] file)
{
RestClient restClient = new RestClient(url);
var request = new RestRequest(Method.POST);
request.AddFileBytes("photo", file, "test");
var response = new RestResponse();
Task.Run(async () =>
{
response = await GetResponseContentAsync(_client, request) as RestResponse;
}).Wait();
string json = response.Content;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question