上传照片 出现expected 705 bytes but received 8192

移动开发 码拜 3年前 (2017-04-15) 1369次浏览
本人做的功能是一个发帖,在打开相机拍照上传的时候出现这个expected 705 bytes but received 8192,上传本地相册的图片没有问题,补充,通过测试 用红米1s ,Nexus 5是可行的,但是用小米5s测试却不行,但是有时候也能上传成功,绝大部分是弹出toast “expected 705 bytes but received 8192”
上传刚拍的图片log
上传照片 出现expected 705 bytes but received 8192
上传本地的图片log
上传照片 出现expected 705 bytes but received 8192
private void UpLoadPhotoOfCamara(String token,String secret,String path){
isCamera = true;
if(!svProgressHUD.isShowing()){
svProgressHUD.showWithStatus(this,getResources().getString(R.string.loadding));
}
GetParamsUtill getParamsUtill = new GetParamsUtill();
getParamsUtill.add(“token”, token);
getParamsUtill.add(“secret”, secret);
Map<String, Object> map = new HashMap<>();
map.put(“uploadFile”, new File(path));
netWorkUtill.uploadTx(getParamsUtill, this, map, NetWorkUtill.GET_REQ_UPLOAD_ACTION);
}
public void uploadTx(GetParamsUtill params, final MyReceiveDataListener receiveDataListener,Map<String,Object> map,final int action) {
postUpload(params, new Callback.CommonCallback<String>() {
@Override
public void onSuccess(String result) {
//                Toast.makeText(x.app(), result, Toast.LENGTH_LONG).show();
//                receiveDataListener.onReceive();
Log.i(“上传”,result);
//                System.out.println(“上传”+result);
String errCode = “”;
String errMsg = “”;
String responseData = “”;
try {
JSONObject jsonObject = new JSONObject(result);
errCode = jsonObject.optString(“errcode”);
errMsg = jsonObject.optString(“errmsg”);
if (“00000000”.equals(errCode)) {
responseData = jsonObject.optJSONArray(“data”).toString();
}
} catch (JSONException e) {
e.printStackTrace();
}
Log.i(“NetWorkUtils”,”接口返回receive”);
receiveDataListener.onReceive(action,errCode,errMsg,responseData);
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show();
Log.i(“NetWorkUtils”,”接口返回error”);
receiveDataListener.onFile(action,ex);
}
@Override
public void onCancelled(CancelledException cex) {
Toast.makeText(x.app(), “cancelled”, Toast.LENGTH_LONG).show();
Log.i(“NetWorkUtils”,”接口返回cancelled”);
receiveDataListener.onFile(action,cex);
}
@Override
public void onFinished() {
}
},Constants.UPLOAD_URL,map);
public void postUpload(GetParamsUtill params,
final Callback.CommonCallback<String> requestCallBack,String url,Map<String,Object> map) {
//        Log.i(“RequestParams”,params.getStringParams().size()+””);
RequestParams requestParams = params.getParams(url);
requestParams.setMultipart(true);
for (Map.Entry<String,Object> entry : map.entrySet()) {
requestParams.addBodyParameter(entry.getKey(),entry.getValue(),null);//new File(entry.getValue())
System.out.println(“BaseNetworkUtill,”+entry.getKey()+”,”+entry.getValue());
}
if (!url.equals(Constants.WEATHER_URL)) {
requestParams.addBodyParameter(“authcode”, addAuth(url));
}
x.http().post(requestParams,requestCallBack);
}
求高手帮忙解答!多谢了
解决方案

20

图片太大了,压缩一下

10

能上传本地照片说明上传模块没问题,你看下是不是拍照时生成的图片名称太长了

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明上传照片 出现expected 705 bytes but received 8192
喜欢 (0)
[1034331897@qq.com]
分享 (0)