公共静态无效createObject1(String bucketName,String file,String filePath){_cosClient.putObject(bucketName,bucket文件,new File(filePath)); System.out.println(“文件为” + _cosClient.listObjects(“知识共享”))); }
@RequestMapping(值=“ / uploadFile”,方法= RequestMethod.POST)公共@ResponseBody字符串uploadFileHandler(@RequestParam(“ name”)字符串名称,@RequestParam(“ file”)MultipartFile文件){
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
File convFile = new File( file.getOriginalFilename());
String fileName= file.transferTo(convFile);
File filePath= convFile.getAbsoluteFile();
System.out.println("file are-"+filePath);
String bucketName = "knowledge-sharing";
objectStorage.createObject1("bucketName", "file", "filePath");
System.out.println(filePath);
return "You successfully uploaded file=" + name;
} catch (Exception e) {
System.err.println(e.getMessage());
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name
+ " because the file was empty.";
}
}