質問編集履歴

2

質問削除の取り消し

2017/11/01 23:31

投稿

cancat
cancat

スコア313

test CHANGED
@@ -1 +1 @@
1
- 回答がない。回答がない。。
1
+ HttpClientでSlackにfileをuploadしたです
test CHANGED
@@ -1 +1,95 @@
1
+ こんにちは。
2
+
3
+ Windows10でWPFのアプリケーションを開発しています。
4
+
5
+ Visual Studio 2017 Communityを使っています。
6
+
7
+ ###前提・実現したいこと
8
+
9
+ HttpClientでSlackにfileをuploadしたいです。
10
+
11
+ ###試したこと
12
+
13
+ 下記コード。
14
+
15
+ ###発生している問題・エラーメッセージ
16
+
17
+ Uploadできない。
18
+
19
+ ###該当のソースコード
20
+
21
+ ```xaml
22
+
23
+ static string token = "**";
24
+
25
+ const string APIBaseLocation = "https://slack.com/api/"; static string uploadfileurl = APIBaseLocation + "files.upload?token=<TOKEN>&pretty=1";
26
+
27
+ public async Task UploadFileAsync(string filefullpath,
28
+
29
+ string[] channelIds)
30
+
31
+ {
32
+
33
+ uploadfileurl = uploadfileurl.Replace("<TOKEN>", token);
34
+
35
+
36
+
1
- 回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。
37
+ //var content = new FormUrlEncodedContent(new Dictionary<string, string>
38
+
39
+ //{
40
+
41
+ // { "token", token },
42
+
43
+ // //{ "filetype", fileType},
44
+
45
+ // { "filename", Path.GetFileName(fileName)},
46
+
47
+ // { "title", Path.GetFileName(fileName)},
48
+
49
+ // { "initial_comment", Path.GetFileName(fileName)},
50
+
51
+ // { "channels", channelIds[0]}
52
+
53
+ //});
54
+
55
+ var array = System.IO.File.ReadAllBytes(filefullpath);
56
+
57
+ var imageContent = new ByteArrayContent(array);
58
+
59
+ imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/*");
60
+
61
+ var client = new HttpClient();
62
+
63
+ client.DefaultRequestHeaders.Add("X-API-TOKEN", token);
64
+
65
+ try
66
+
67
+ {
68
+
69
+ var response = await client.PostAsync(uploadfileurl, imageContent);
70
+
71
+ }
72
+
73
+ catch (Exception exception)
74
+
75
+ {
76
+
77
+ string error = exception.Message;
78
+
79
+ }
80
+
81
+ ```
82
+
83
+ ###補足情報(言語/FW/ツール等のバージョンなど)
84
+
85
+ Microsoft Visual Studio Community 2017
86
+
87
+ Version 15.0.26228.9 D15RTWSVC
88
+
89
+ Microsoft .NET Framework
90
+
91
+ Version 4.6.01586
92
+
93
+ です。
94
+
95
+ よろしくお願いします。

1

回答がない。

2017/11/01 23:31

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- HttpClientでSlackにfileをuploadしたです
1
+ 回答がない。回答がない。。
test CHANGED
@@ -1,111 +1 @@
1
- こんにちは。
2
-
3
- Windows10でWPFのアプリケーションを開発しています。
4
-
5
- Visual Studio 2017 Communityを使っています。
6
-
7
-
8
-
9
- ###前提・実現したいこと
10
-
11
- HttpClientでSlackにfileをuploadしたいです。
12
-
13
-
14
-
15
- ###試したこと
16
-
17
- 下記コード。
18
-
19
-
20
-
21
- ###発生している問題・エラーメッセージ
22
-
23
- Uploadできない。
24
-
25
-
26
-
27
- ###該当のソースコード
28
-
29
- ```xaml
30
-
31
- static string token = "**";
32
-
33
- const string APIBaseLocation = "https://slack.com/api/"; static string uploadfileurl = APIBaseLocation + "files.upload?token=<TOKEN>&pretty=1";
34
-
35
- public async Task UploadFileAsync(string filefullpath,
36
-
37
- string[] channelIds)
38
-
39
- {
40
-
41
- uploadfileurl = uploadfileurl.Replace("<TOKEN>", token);
42
-
43
-
44
-
45
- //var content = new FormUrlEncodedContent(new Dictionary<string, string>
1
+ 回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。回答がない。
46
-
47
- //{
48
-
49
- // { "token", token },
50
-
51
- // //{ "filetype", fileType},
52
-
53
- // { "filename", Path.GetFileName(fileName)},
54
-
55
- // { "title", Path.GetFileName(fileName)},
56
-
57
- // { "initial_comment", Path.GetFileName(fileName)},
58
-
59
- // { "channels", channelIds[0]}
60
-
61
- //});
62
-
63
-
64
-
65
- var array = System.IO.File.ReadAllBytes(filefullpath);
66
-
67
- var imageContent = new ByteArrayContent(array);
68
-
69
- imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/*");
70
-
71
-
72
-
73
- var client = new HttpClient();
74
-
75
- client.DefaultRequestHeaders.Add("X-API-TOKEN", token);
76
-
77
- try
78
-
79
- {
80
-
81
- var response = await client.PostAsync(uploadfileurl, imageContent);
82
-
83
- }
84
-
85
- catch (Exception exception)
86
-
87
- {
88
-
89
- string error = exception.Message;
90
-
91
- }
92
-
93
- ```
94
-
95
-
96
-
97
- ###補足情報(言語/FW/ツール等のバージョンなど)
98
-
99
- Microsoft Visual Studio Community 2017
100
-
101
- Version 15.0.26228.9 D15RTWSVC
102
-
103
- Microsoft .NET Framework
104
-
105
- Version 4.6.01586
106
-
107
-
108
-
109
- です。
110
-
111
- よろしくお願いします。