1. 程式人生 > >檔案圖片上傳

檔案圖片上傳

File.separator 分割付
String dir = savePath + File.separator+Common.QRCODE+File.separator + subpath +File.separator + batchCode;
File outputFile = new File(dir);//根據路建立檔案類例項
outputFile.mkdirs();//建立資料夾路徑

boolean mkdir() 建立此抽象路徑名指定的目錄。 比如建立E:\\text  沒有 E 報錯返回false
boolean mkdirs() 建立此抽象路徑名指定的目錄,包括所有必需但不存在的父目錄。 比如建立E:\\text  沒有 E建立E

String str = String.format("http://app.diandiancaidan.com/scan.do?m=nscan&qrCode=%s", nn);
QrCodeHelper.saveqrCode(dir,str, nn, "0");
public static void saveqrCode(String dir, String data, String filename,String flag){   
    try
    {
        int width = 640; 
        int height = 640; 
if("1".equals(flag)){ width =580; height = 580; }else if("2".equals(flag)){ width =586; height = 586; } String format = "png"; Hashtable<EncodeHintType, String> hints= new Hashtable<EncodeHintType
, String>(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); BitMatrix bitMatrix = new MultiFormatWriter().encode(data, BarcodeFormat.QR_CODE, width, height,hints); //圖片 File outputFile = new File(dir + "/" + filename + ".png"); //之前建立的路徑加上圖片路徑 MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile); //createQRCode(bitMatrix, format, outputFile); } catch(Exception e) { e.printStackTrace(); } }
本地傳輸測試使用

String path=(Class.class.getClass().getResource("/").getPath()+String.format(Common.agentPath,super.userId,Common.normal)).substring(1);

D:/DDCDSS/management/web/target/classes/ static/upload/shop/shop-1/thumb/normal

<img class="layui-upload-img" id="${imgId}old" src="'../../${value}"/> static/upload/shop/shop-1/thumb/normal/1542249116725.jpg