在springboot配置文件中添加
upload.path = D://profile//
upload.internet.path = http://39.98.246.180:8080/xinfang/profile/
@Controller
@RequestMapping("file")
public class AdvertiseController
{
@Value("${upload.path}")
private String URL;
@Value("${upload.internet.path}")
private String NETURL;
@RequestMapping("/add")
@ResponseBody
public Msg videoUpdate(MultipartFile file[], String orgId)
{
List<String> pathList = new ArrayList<String>();
for (int i = 0; i < file.length; i++)
{
String realPath = URL + file[i].getOriginalFilename();
String netPath = NETURL + file[i].getOriginalFilename();
System.out.println(realPath);
File tempFile = new File(realPath);
try
{
file[i].transferTo(tempFile);
} catch (IllegalStateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
pathList.add(netPath);
}
return Msg.success().add("list", pathList).add("orgId", orgId);
}
@RequestMapping("/delete")
@ResponseBody
public Msg videoDelete(String fileName)
{
String realFilePath = fileName.replace(NETURL, URL);
File file = new File(realFilePath);
if (file.exists() && file.isFile())
{
if (file.delete())
{
return Msg.success().add("msg", "删除单个文件" + fileName + "成功!");
} else
{
return Msg.fail().add("errorMsg", "删除单个文件" + fileName + "失败!");
}
} else
{
return Msg.fail().add("errorMsg", "删除单个文件失败:" + fileName + "不存在!");
}
}