亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

上傳文件的cURL命令不上傳文件

上傳文件的cURL命令不上傳文件

慕田峪9158850 2022-11-30 16:54:41
所以我有一個 Java API,我使用 cURL 命令向我的 API 發送 GET/POST 請求。我在我的 Java API 中使用 Springboot。我的 cURL 命令如下所示:curl -X POST \  https://localhost:8443/abc/code/v \  -H 'Content-Type: multipart/form-data' \  -F file=@/path/to/file.txt接收此請求的 Java Springboot 方法如下所示:@RequestMapping(method = RequestMethod.POST, value = "/{code}/{v}")    public ResponseEntity<Object> uploadTemplate( //            @ApiParam(value = "code desc") //            @PathVariable final String code, //            @ApiParam(value = "v desc") //            @PathVariable final String v, //            @RequestParam("file") MultipartFile file    ) throws IOException {        //log.info("received [url: /tabc/" + code + "/" + v + ", method: POST");        System.out.println("file: "+ file.getName());}打印出來"file: file"它看起來根本不像file.txt是上傳到服務器!我究竟做錯了什么?我查過谷歌,但看起來我幾乎什么都做了。
查看完整描述

1 回答

?
弒天下

TA貢獻1818條經驗 獲得超8個贊

MultipartFile.getName返回多部分形式的參數名稱。

獲取MultipartFile使用的字節file.getBytes()

如果你MultipartFile是一個文本文件,你可以使用這個實用方法來檢索該文本文件中的行列表:

 public List<String> read(MultipartFile file) throws IOException {

        InputStreamReader in = new InputStreamReader(file.getInputStream());

        try (BufferedReader reader = new BufferedReader(in)) {

            return reader.lines().collect(Collectors.toList());

        }

    }

GitHub 上的完整代碼


查看完整回答
反對 回復 2022-11-30
  • 1 回答
  • 0 關注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號