文件上传:
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
public JSONObject handleFileUpload(MultipartFile file, String filePath,String url) {
JSONObject result = new JSONObject();
if (!file.isEmpty()) {
try {
File parentDir = new File(filePath);
if (!parentDir.exists()){
parentDir.mkdirs();
}
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(filePath+file.getOriginalFilename())));
out.write(file.getBytes());
out.flush();
out.close();
logger.info("filePath=={} write over!", file