簡體   English   中英

如何使用 Spring 引導在 Java 中測試 Dropbox 上傳?

[英]How to test a dropbox upload in Java with Spring Boot?

我有以下代碼片段:

@RestController
@RequestMapping("/dropbox")
public class DropboxController {

    private static final Logger logger = LoggerFactory.getLogger(DropboxController.class);

    @Autowired
    DropboxService dropboxService;

    @Autowired
    DbxClientV2 dropboxClient;

    @PostMapping("/upload")
    public String handleFileUplad(@RequestParam("file") MultipartFile file, @RequestParam("filePath") String filePath) throws Exception {
        dropboxService.uploadFile(file, filePath);
        return "You successfully uploaded " + filePath + "!!";
    }

現在我想測試上傳是否有效。 我怎樣才能做到這一點? 當我嘗試使用 curl 時,語法會如何?

資料來源: https://www.mkyong.com/spring/curl-post-request-examples/

要使用文件發布,請添加此 -F file=@"path/to/data.txt"

$ curl -F file=@"path/to/data.txt" http://localhost:8080/dropbox/upload

作為替代方案,您可以使用 Postman 添加表單數據作為帶有 2 個參數的正文和 select 將類型作為文件

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM