[code]/**
* 描述:向服务端上传pdf文件 *
* @param filename
* 文件名
* @param base64StringData
* 文件数据
* @return
*/
public static String uploadFile(String filename, String base64StringData) {
String pdfurl = TestPdf.class.getClassLoader().getResource("").getPath();//TestPdf 是当前类的类名
pdfurl = pdfurl.substring(1, pdfurl.length());
pdfurl = pdfurl.replace("/WEB-INF/classes/", "");//文件存放路径 (可写绝对路径)
BASE64Decoder decoder = new BASE64Decoder();
try {
//将base64编码的字符串解码成字节数组
byte bytes[] = decoder.decodeBuffer(base64StringData);
FileOutputStream out = new FileOutputStream(pdfurl + "/pdf/" + filename);
out.write(bytes);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return "http://localhost:8080/TestS/pdf/"+filename;
}