package com.ntlab.irisserver.utils;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Base64;
public class Base64Decode {
public static String saveAsFile(String rid ,Integer dno ,String path1 ,String enimage) throws IOException {
//デコードを行う
byte[] dedata = Base64.getDecoder().decode(enimage);
//ファイルがないときは作成する
String fileName = "r" + rid + "d" + dno.toString() + ".png";
String path2 = "/gallery/"+ rid + "/"+ dno.toString();
String path = path1 + path2 + "/" + fileName;
System.out.println(path.toString());
File file = new File(path);
System.out.println("1" + path.toString());
file.getParentFile().mkdirs();
System.out.println("2"+ path.toString());
file.createNewFile();
System.out.println("3 koregarogu" + path.toString());
//ファイルに画像データを書き込む
FileOutputStream file1 = new FileOutputStream(file, false);
BufferedOutputStream bf = new BufferedOutputStream(file1);
bf.write(dedata, 0, dedata.length);
//ファイルを閉じる
bf.close();
//セーブしたファイルの相対パスを文字列として返す
return path;
}
}