R
R
ruslannafisovich2017-09-04 23:28:08
In contact with
ruslannafisovich, 2017-09-04 23:28:08

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

As a result, I get the error "413 Request Entity Too Large"
Do you have your own solutions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2017-09-05
@petermzg

The error indicates that the server did not accept the data due to its large size.
Explicitly exposed limit on the server. Zoom it in.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question