I'm trying to Upload Track to sound cloud. So far i'm successfully able to get auth token but when i tried to 'PostAsync' it throws exception
A Task was canceled. I have also set the timeout value but still the same error. Issue seems to be something wrong with what i'm doing. Below is the code which i'm using and i have taken it from stack overflow but with no luck.
private async Task<bool> StartUploadAsync(PubVidoInfo pubStuff)
{
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.ConnectionClose = true;
httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Mixcraft", "1.0"));
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
ByteArrayContent titleContent = new ByteArrayContent(Encoding.UTF8.GetBytes(pubStuff.title));
ByteArrayContent descriptionContent = new ByteArrayContent(Encoding.UTF8.GetBytes(pubStuff.description));
ByteArrayContent sharingContent = null;
if (pubStuff.publishedFileState == PubFileState.PF_Public)
{
sharingContent = new ByteArrayContent(Encoding.UTF8.GetBytes("public"));
}
else
{
sharingContent = new ByteArrayContent(Encoding.UTF8.GetBytes("private"));
}
ByteArrayContent byteArrayContent = new ByteArrayContent(File.ReadAllBytes(pubStuff.pubFilePath));
byteArrayContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
MultipartFormDataContent content = new MultipartFormDataContent();
content.Add(titleContent, "track[title]");
content.Add(descriptionContent, "track[description]");
content.Add(sharingContent, "track[sharing]");
content.Add(byteArrayContent, "track[asset_data]", Path.GetFileName(pubStuff.pubFilePath));
try
{
HttpResponseMessage message = await httpClient.PostAsync(new Uri("https://api.soundcloud.com/tracks"), content);
if (message.IsSuccessStatusCode)
{
PubUploadStatus = PubUploadStatus.US_Finished;
}
else
{
PubUploadStatus = PubUploadStatus.US_Failed;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
PubUploadStatus = PubUploadStatus.US_Failed;
}
return true;
}
Is there any thing i'm doing ? Can any one point out the issue in particular code.
Regards,