File upload in xamarin forms

Moon
1
Reputation point
I want to upload image from mobile application. Here is the mobile side code
public async Task<bool> UploadFile(string fileName,byte[] imageBytes = null)
{
bool isSuccess = false;
try
{
if (imageBytes != null && imageBytes.Length > 0)
{
MultipartFormDataContent imageRequest = new MultipartFormDataContent();
ByteArrayContent byteArrayContent = new ByteArrayContent(imageBytes);
imageRequest.Add(byteArrayContent, "Files", fileName);
if (_appService.IsApiAvailable().Result)
{
string url = FileUploadEndpoint;
isSuccess = await _requestProvider.PostAsync<MultipartFormDataContent, bool>(url, imageRequest, accessToken, null).ConfigureAwait(false);
}
}
}
catch (Exception ex)
{
Support.Error.Show(ex);
}
return isSuccess;
}
Here is the API side code
public bool PostAsync([FromForm]FilesUploadRequest filesUploadRequest)
{
//some code
}
public class FilesUploadRequest
{
public List<IFormFile> Files { get; set; }
}
Response from API is always coming false though it is working fine from swagger. Can anyone suggest me where I am doing wrong?