简体   繁体   中英

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

I have the following code snippet:

@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 + "!!";
    }

Now I want to test whether the upload works. How can I do this? How would be the syntax when I try it with curl?

Source: https://www.mkyong.com/spring/curl-post-request-examples/

To POST with a file, add this -F file=@"path/to/data.txt"

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

Also as an alternative you can use Postman Add form-data as body with 2 parameters and select the type as file

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM