Click here to Skip to main content
15,918,178 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,
I know there are at lot information about this item, but any of them work for me(maybe, or not maybe, i am doing something wrong):

This is the WEB API and the code to avoid the error

[HttpPost]
[DisableRequestSizeLimit]
[RequestSizeLimit(100_000_000)]
[RequestFormLimits(MultipartBodyLengthLimit = 100_000_000)]

In the web.config i have

<httpruntime ..="" maxrequestlength="...">

<system.webserver>
<security>
<requestfiltering>
<requestlimits maxallowedcontentlength="524288000">



and nothing
I am using XAMARIN VS 2022, this is the api

var file = await MediaPicker.CapturePhotoAsync();
if (file == null) return;
var content = new MultipartFormDataContent();
content.Add(new StreamContent(await file.OpenReadAsync()), "file", file.FileName);
string url = "https://10.0.2.2:7254/Api/getData";
var response = await client.PostAsync(url,content);

What I have tried:

I have read at lot of information
Posted
Comments
mtoha 17-Apr-23 9:19am    
what is client in this line? var response = await client.PostAsync(url,content);
Are you want to upload file more than 16384? What is correct size? in byte or Kb? WEB API built with .net core or .net? what version of .net (core)
Luis M. Rojas 17-Apr-23 10:21am    
What is client in this line?
These lines:
#if DEBUG
HttpClientHandler insecureHandler = DependencyService.Get<ihttpclienthandlerservice>().GetInsecureHandler();
HttpClient client = new HttpClient(insecureHandler);
#else
HttpClient client = new HttpClient();
#endif

Are you want to upload file more than 16384?
Not, i am just taking a picture with these lines:
var file = await MediaPicker.CapturePhotoAsync() ;
if (file == null) return;
var content = new MultipartFormDataContent();
content.Add(new StreamContent(await file.OpenReadAsync()), "file", file.FileName);
Web API built with..? ASP.NET CORE
mtoha 17-Apr-23 11:17am    
I usually using get method. i.e. you want to get picture, so the web api read files from server, and return base64 string.
and client (xamarin) decode from base64 to image.
for read file using get method, there is no file size restriction as I know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900