こんにちは。
Windows10でWPFのアプリケーションを開発しています。
Visual Studio 2017 Communityを使っています。
###前提・実現したいこと
HttpClientでSlackにfileをuploadしたいです。
###試したこと
下記コード。
###発生している問題・エラーメッセージ
Uploadできない。
###該当のソースコード
xaml
1 static string token = "**"; 2 const string APIBaseLocation = "https://slack.com/api/"; static string uploadfileurl = APIBaseLocation + "files.upload?token=<TOKEN>&pretty=1"; 3 public async Task UploadFileAsync(string filefullpath, 4 string[] channelIds) 5 { 6 uploadfileurl = uploadfileurl.Replace("<TOKEN>", token); 7 8 //var content = new FormUrlEncodedContent(new Dictionary<string, string> 9 //{ 10 // { "token", token }, 11 // //{ "filetype", fileType}, 12 // { "filename", Path.GetFileName(fileName)}, 13 // { "title", Path.GetFileName(fileName)}, 14 // { "initial_comment", Path.GetFileName(fileName)}, 15 // { "channels", channelIds[0]} 16 //}); 17 var array = System.IO.File.ReadAllBytes(filefullpath); 18 var imageContent = new ByteArrayContent(array); 19 imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/*"); 20 var client = new HttpClient(); 21 client.DefaultRequestHeaders.Add("X-API-TOKEN", token); 22 try 23 { 24 var response = await client.PostAsync(uploadfileurl, imageContent); 25 } 26 catch (Exception exception) 27 { 28 string error = exception.Message; 29 }
###補足情報(言語/FW/ツール等のバージョンなど)
Microsoft Visual Studio Community 2017
Version 15.0.26228.9 D15RTWSVC
Microsoft .NET Framework
Version 4.6.01586
です。
よろしくお願いします。
あなたの回答
tips
プレビュー