StatusCode: 404, ReasonPhrase: Not Found', Version: 1.1
i need help i keep getting this error locally it works when posting an image through post man but from my xamarin forms app to the local iis server i get this error {StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Cache-Control: no-cache Date: Mon, 23 Nov 2020 18:59:20 GMT Pragma: no-cache Server: Microsoft-IIS/10.0 Transfer-Encoding: chunked X-Android-Received-Millis: 1606157960091 X-Android-Response-Source: NETWORK 404 X-Android-Selected-Protocol: http/1.1 X-Android-Sent-Millis: 1606157959793 X-Powered-By: ASP.NET Expires: -1 }}
private async void ImageButton_Clicked(object sender, System.EventArgs e)
{
var file = await MediaPicker.PickPhotoAsync();
if (file == null)
return;
var content = new MultipartFormDataContent();
//var u = await file.OpenReadAsync();
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("multipart/form-data");
content.Add(new StreamContent(await file.OpenReadAsync()), "file", file.FileName);
// Store single transcient instance of client data store
var scopedClientDataStore = ClientDataStore;
// Get the user token
var token = (await scopedClientDataStore.GetLoginCredentialsAsync())?.Token;
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
var m = await httpClient.PostAsync(RouteHelpers.GetAbsoluteRoute(PictureApiRoutes.Upload, AppSetting.JPRServer2), content); }
private async Task<ApiResponse<ReportImageApiModel>> PictureUploadAsync(IFormFile file, string user, string path)
{
var httpContext = HttpContext.Request;
var image = httpContext.Form.Files.FirstOrDefault();
//The file name
FileName = image.FileName;
//Get the image file extension
Extension = Path.GetExtension(FileName);
//Check if its a valid file extension
if (!AllowedExtensions.Contains(Extension))
//return an error message
return new ApiResponse<ReportImageApiModel>() { ErrorMessage = "Not a valid file extension" };
//The new filename to be stored with
var newFileName = $"{user}{Guid.NewGuid()}{Extension}";
var LocalPath = Path.Combine(_Environment.WebRootPath, "Media", $"{path}");
//The File Path to store the image
var filePath = Path.Combine(_Environment.WebRootPath, "Media", $"{path}", newFileName);
if (!Directory.Exists(LocalPath))
Directory.CreateDirectory(LocalPath);
//
using var fileStream = new MemoryStream();
//upload the file content to the file stream
await image.CopyToAsync(fileStream);
System.IO.File.WriteAllBytes(filePath, fileStream.ToArray());
return new ApiResponse<ReportImageApiModel>() { Response = new ReportImageApiModel { ImageName = newFileName } };
}