PostMan一次性上传多个文件
作者:互联网
使用场景:
需要从本地一次性上传多张图片导入到数据库,或者在本地调试一次性上传多个文件到后台
1、本地PostMan上传多个文件设置:
2、后台接口对应代码如下:
@PostMapping("/uploadMinIO") public CommonResult upload(@RequestParam(name = "file", required = false) List<MultipartFile> file) { if (file == null || file.size() == 0) { return CommonResult.failed("上传文件不能为空"); } List<String> orgfileNameList = new ArrayList<>(file.size()); List<String> urlList = new ArrayList<>(); for (MultipartFile multipartFile : file) { String orgfileName = multipartFile.getOriginalFilename(); orgfileNameList.add(orgfileName); try { //文件上传 InputStream in = multipartFile.getInputStream(); String datePath = new DateTime().toString("yyyyMMddHHmmssSSS"); String filename = "pic/" + datePath + orgfileName.substring(orgfileName.lastIndexOf(".")); minioClient.putObject(PutObjectArgs.builder() .bucket(bucketName) .object(filename) .stream(in, multipartFile.getSize(), -1) .contentType(multipartFile.getContentType()) .build()); in.close(); String url = minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs .builder() .bucket(bucketName) .method(Method.GET) .object(filename).build()); urlList.add(url); } catch (Exception e) { log.error(e.getMessage()); return CommonResult.failed("上传失败"); } } Map<String, Object> data = new HashMap<String, Object>(); data.put("bucketName", bucketName); data.put("fileName", orgfileNameList); data.put("url", urlList); return CommonResult.success(data, "上传成功"); }
这里参数file使用postman中对应的file参数名,使用集合类型接收多个文件,下面示例代码最终将上传的图片上传到minio服务器存储
————————————————
版权声明:本文为CSDN博主「Fly_Camel_Yu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_39974348/article/details/121740721
标签:PostMan,一次性,上传,bucketName,file,multipartFile,data,String 来源: https://www.cnblogs.com/wwssgg/p/16307929.html