Hello,
I noticed that you uploaded the file using the GET request, which is not officially recommended by .net. According to HTTP semantics, the GET request should be used to read server resources, the PUT request and the POST request should be used to modify server resources, and GET and PUT should be idempotent operations, while POST does not guarantee idempotence.
Therefore, the Post request is usually used to add files, and the Put request is used to modify existing files on the server.
For your needs of uploading files, you can refer to the following .net commonly used form method to upload files to the server. And test its efficiency difference on Xamarin and Maui.
var filePath = @"file_path";
using (var multipartFormContent = new MultipartFormDataContent())
{
//Load the file and set the file's Content-Type header
var fileStreamContent = new StreamContent(File.OpenRead(filePath));
fileStreamContent.Headers.ContentType = new MediaTypeHeaderValue("filetype eg:image/png");
//Add the file
multipartFormContent.Add(fileStreamContent, name: "file", fileName: "filename.xxx");
//Send it
var response = await httpClient.PostAsync("upload_url", multipartFormContent);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.