InputStream fis;
try {
fis = new FileInputStream(params[0]+params[1]);//params[0]为文件路径,params[1]为文件名称
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int count =-1;
String uploadBuffer = null ;
try {
while((count = fis.read(buffer))!=-1){
baos.write(buffer, 0, count);
uploadBuffer=Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT); //进行Base64编码Base64.DEFAULT这个不能换成count
}
SoapObject soapObject=webServiceBase.getBaseSimpleData(params[1],uploadBuffer,"getImageFromAndroid",AgbcApi.TASKSERVICEURL);
reque=soapObject.getProperty(0).toString();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
public String getImageFromAndroid(String filename, String image){
OutputStream fos = null;
try{
Date date=new Date();
DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
String time=format.format(date);
String toDir = "d:\\Program Files\\images\\"+time+"\\"; //存储路径
byte[] buffer = new BASE64Decoder().decodeBuffer(image); //对android传过来的图片字符串进行解码
File destDir = new File(toDir);
if(!destDir.exists())
destDir.mkdir();
fos = new FileOutputStream(new File(toDir,filename)); //保存图片
fos.write(buffer);
fos.flush();
fos.close();
return "上传图片成功!" + "图片路径为:" + toDir;
}catch (Exception e){
e.printStackTrace();
}
return "上传图片失败!";
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有