图片文件上传以及图片文件流上传
来源:互联网 发布:市政工程算量软件 编辑:程序博客网 时间:2024/06/02 08:59
/**
* file文件 上传图片至服务器
* */
public void uploadImage() {
File temp = new File(ImageUtil.getPhotoAbsolutePath(),
ImageUtil.getCropPhotoName());
RequestParams params = new RequestParams();
MultipartEntity entity = new MultipartEntity();
try {
entity.addPart("username",
new StringBody(Setting.getCurrentMerchantPhone()));
entity.addPart("password",
new StringBody(Setting.getCurrentUserPwd()));
entity.addPart("image", new FileBody(temp, "multipart/form-data"));
params.setBodyEntity(entity);
LogUtil.i(TAG, "" + temp);
HttpUtils http = new HttpUtils();
http.send(HttpRequest.HttpMethod.POST, Constants.Portrait, params,
new RequestCallBack<String>() {
@Override
public void onFailure(HttpException error, String msg) {
// 网络访问不成功
}
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
if (responseInfo != null) {
LogUtil.d(TAG, "upload success "
+ responseInfo.result);
String result = responseInfo.result;
LoginInfo loginInfo = GsonTools
.changeGsonToBean(result,
LoginInfo.class);
if (loginInfo.getCode() == Constants.SUCCESSFUL_CODE) {
// 清除指定URL的内存、磁盘缓存
mBitmapUtils.clearCache(Setting
.getCurrentUserPortrait());
// 清空内存、磁盘缓存
// mBitmapUtils.clearCache();
Setting.setCurrentUserPortrait(loginInfo
.getResult().getPortrait());
}
ToastUtil.TextToast(mContext,
loginInfo.getMsg(), 0);
}
}
});
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
二
try {
if (data != null) {
Bundle extras = data.getExtras();
bitmap = extras.getParcelable("data");
//this.iv_head_img.setImageBitmap(bitmap);
// tempFile.delete();//删除本地文件
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 70, stream);
byte[] byteArray = stream.toByteArray();
InputStream is = new ByteArrayInputStream(byteArray);
OutputStream outStream = new ByteArrayOutputStream();// 输出到内存
int len = 0;
byte[] buffer = new byte[1024];
while ((len = is.read(buffer)) != -1) {
outStream.write(buffer, 0, len);//
}
byte[] content_byte = ((ByteArrayOutputStream) outStream).toByteArray();
InputStream is2 = new ByteArrayInputStream(((ByteArrayOutputStream) outStream).toByteArray());
uploadHeadImage(Setting.getTelphone(), content_byte, is2);
}
} catch (Exception e) {
e.printStackTrace();
}
RequestParams requestParams = new RequestParams();
requestParams.addBodyParameter("telphone", telphone);
requestParams.addBodyParameter("image", is, bytes.length, "portrait_1.png", ".png");
if (data != null) {
Bundle extras = data.getExtras();
bitmap = extras.getParcelable("data");
//this.iv_head_img.setImageBitmap(bitmap);
// tempFile.delete();//删除本地文件
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 70, stream);
byte[] byteArray = stream.toByteArray();
InputStream is = new ByteArrayInputStream(byteArray);
OutputStream outStream = new ByteArrayOutputStream();// 输出到内存
int len = 0;
byte[] buffer = new byte[1024];
while ((len = is.read(buffer)) != -1) {
outStream.write(buffer, 0, len);//
}
byte[] content_byte = ((ByteArrayOutputStream) outStream).toByteArray();
InputStream is2 = new ByteArrayInputStream(((ByteArrayOutputStream) outStream).toByteArray());
uploadHeadImage(Setting.getTelphone(), content_byte, is2);
}
} catch (Exception e) {
e.printStackTrace();
}
RequestParams requestParams = new RequestParams();
requestParams.addBodyParameter("telphone", telphone);
requestParams.addBodyParameter("image", is, bytes.length, "portrait_1.png", ".png");
0 0
- 图片文件上传以及图片文件流上传
- [上传]文件上传以及图片处理(转)
- 图片、文件表单上传以及异步上传
- java 上传文件以及各种视频图片!
- PHP 远程上传图片以及文件
- java 上传文件以及各种视频图片!
- 文件上传,图片上传案例
- html5图片上传【文件上传】
- c#文件流上传图片
- ios文件流上传图片
- 上传文件,图片代码
- 图片文件上传代码
- 文件、图片上传
- 文件图片上传.JSP
- 文件或图片上传
- 文件上传(图片)
- 图片文件上传
- 图片文件上传
- Conversion to Dalvik format failed with error 1
- 数据截取的问题
- Jquery基础初探
- php连接sqlserver数据库服务器(或者称mssql数据库)的几种方法
- http://netfilter.org/ 读后感
- 图片文件上传以及图片文件流上传
- 原码补码反码以及位运算符
- Java使用极小的内存完成对超大数据的去重计数,用于实时计算中统计UV
- Hibernate单表开发步骤
- HTML第二课:表格、表单和框架
- Django笔记 CMS框架Mezzanine 2
- 异常
- JavaScript的变量作用域
- Ambari警报功能分析及源码解读