File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,28 @@ class HttpclientController extends Controller {
104
104
ctx . body = result . data . files ;
105
105
}
106
106
107
+ // https://github.com/node-modules/urllib/pull/322
108
+ async files ( ) {
109
+ const ctx = this . ctx ;
110
+
111
+ const result = await ctx . curl ( 'https://httpbin.org/post' , {
112
+ // 必须指定 method,支持 POST,PUT
113
+ method : 'POST' ,
114
+ // 上传文件
115
+ files : {
116
+ file1 : __filename ,
117
+ file2 : Buffer . from ( 'mock file content' ) ,
118
+ } ,
119
+ // 其他 Field
120
+ data : {
121
+ foo : 'bar' ,
122
+ } ,
123
+ // 明确告诉 httpclient 以 JSON 格式处理响应 body
124
+ dataType : 'json' ,
125
+ } ) ;
126
+ ctx . body = result . data . files ;
127
+ }
128
+
107
129
async postStream ( ) {
108
130
const ctx = this . ctx ;
109
131
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module.exports = app => {
8
8
app . router . get ( '/delete' , 'httpclient.del' ) ;
9
9
app . router . get ( '/form' , 'httpclient.form' ) ;
10
10
app . router . get ( '/multipart' , 'httpclient.multipart' ) ;
11
+ app . router . get ( '/files' , 'httpclient.files' ) ;
11
12
app . router . get ( '/stream' , 'httpclient.stream' ) ;
12
13
app . router . post ( '/stream' , 'httpclient.postStream' ) ;
13
14
app . router . get ( '/error' , 'httpclient.error' ) ;
You can’t perform that action at this time.
0 commit comments