public static void main2(String[] args) {
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);
try {
String filepath = "/XX/XX1.ipa";//D盘下的file文件夹的目录
File file = new File(filepath);//File类型可以是文件也可以是文件夹
File pdf = file;
FileInputStream fileInputStream = null;
fileInputStream = new FileInputStream(pdf);
MultipartFile multipartFile = new MockMultipartFile(pdf.getName(), pdf.getName(),
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
// 文件路径
File apkFile = new File("/XX/xx1" + File.separator + "test");
FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), apkFile);
HttpResponse httpFileUploadRequest = null;
Map<String, String> resultMap = new HashMap<>();
String html = "";
// 参数
// JSONObject token = getToken();
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("test1", "tt");
jsonObject1.put("test2", "tt");
HashMap<String, Object> paramMaps = new HashMap<>();
paramMaps.put("param", jsonObject1);
paramMaps.put("tt1", new File(apkFile.getAbsolutePath()));
// header
HashMap<String, String> headersMaps = new HashMap<>();
try {
httpFileUploadRequest = com.bangcle.app.utils.HttpUtils.httpFileUploadRequest(
"http://xx.xx.xx.xxx:8080" + "/test1", paramMaps, headersMaps, null, null,
null,
null);
JSONObject result = JSONObject
.parseObject(httpFileUploadRequest.html());
System.out.println(result);
} catch (Exception e) {
logger.error("上传文件时异常,文件名:{}", e, "file.getAbsolutePath()");
resultMap.put(ResultCode.FAIL, "上传失败");
}
System.out.println("1");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
模拟MultipartFile上传文件
最新推荐文章于 2024-06-29 03:21:32 发布
本文详细介绍了如何在Java中使用MultipartFile接口处理文件上传,包括上传步骤、常见问题及解决策略,帮助开发者掌握文件上传的核心技术。
3215

被折叠的 条评论
为什么被折叠?



