您的位置:首页 > 编程语言 > Java开发

Java后台服务器接收IOS客户端上传的图片

2015-04-01 15:15 435 查看
// 定义变量存储图片地址

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端代码链接:/article/7953365.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: