File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 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 {
104104 ctx . body = result . data . files ;
105105 }
106106
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+
107129 async postStream ( ) {
108130 const ctx = this . ctx ;
109131
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module.exports = app => {
88 app . router . get ( '/delete' , 'httpclient.del' ) ;
99 app . router . get ( '/form' , 'httpclient.form' ) ;
1010 app . router . get ( '/multipart' , 'httpclient.multipart' ) ;
11+ app . router . get ( '/files' , 'httpclient.files' ) ;
1112 app . router . get ( '/stream' , 'httpclient.stream' ) ;
1213 app . router . post ( '/stream' , 'httpclient.postStream' ) ;
1314 app . router . get ( '/error' , 'httpclient.error' ) ;
You can’t perform that action at this time.
0 commit comments