繁体   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