// 定义变量存储图片地址
String imagePath="";
// 接收图片数据 (base64)
String image=httpRequest.getParameter("image");
try{
// 将base64 转 字节数组
Base64 base=new Base64();
byte[]decode=base.decode(image);
// 图片输出路径
imagePath=commodityFilePath+"/"+System.currentTimeMillis()+".png";
// 定义图片输入流
InputStream fin=new ByteArrayInputStream(decode);
// 定义图片输出流
FileOutputStream fout=new FileOutputStream(imagePath);
// 写文件
byte[]b=new byte[1024];
int length=0;
while((length=fin.read(b))>0){
fout.write(b,0,length);
}
// 关闭数据流
fin.close();
fout.close();
}catch(Exception e){
e.printStackTrace();
}
IOS端代码链接:http://blog.csdn.net/z18694516069/article/details/44806867
Java后台服务器接收IOS客户端上传的图片
最新推荐文章于 2021-03-29 16:23:34 发布