I am having a model which consists of following parameters
public class FileExchangeDetails
{
public Guid SenderId { get; set; }
public List<Files> Files { get; set; }
public Guid Id { get; set; }
}
public class Files
{
public string FilePath { get; set; }
public string FileName { get; set; }
public byte[] FileBytes { get; set; }
public string FileType { get; set; }
}
I am sending the file data(Image or File) with FileExchangeDetails
using following
public static async Task<string> PostFilesToToApi(string apiUrl, FileExchangeDetails exchangeDetails)
{
try
{
using (var httpreqclient = new httpclient())
{
httpreqclient.baseaddress = new uri(string.format(apiurls.weburl, application.current.properties["currentsitename"]));
httpreqclient.defaultrequestheaders.add("authorization", "bearer " + applicationcontext.accesstoken);
httpreqclient.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json"));//accept header
var content = jsonconvert.serializeobject(exchangedetails, formatting.none);
var stringcontentinput = new stringcontent(content, encoding.utf8, "application/json");
var response = await httpreqclient.postasync(new uri(string.format(apiurls.weburl, application.current.properties["currentsitename"]) + apiurl), stringcontentinput);
var stringasync = await response.content.readasstringasync();
if (response.issuccessstatuscode)
{
var responsejson = stringasync;
return responsejson;
}
}
}
catch (Exception exception)
{
LoggingManager.Error(exception, "PostFilesToToApi", "ApiWrapper");
}
return null;
}
Functionally everything are working fine but now I need to display percentage of file uploaded while it is uploading to server.
I have few guidelines with web client but for that the parameters are only byte[] or string.
How to get that % data with httpclient. Can someone please help me with this.