android文件传输没有照片的文件夹,android-打开失败:使用POST将图片上传到网站时,ENOENT(无此类文件或目录)...

我将图像的Uri字符串保存为SQLite作为字符串.我可以通过为其创建视图意图来查看图像.

但是当我使用FileBody(new File(theUriFromTheDatabase))将图像上传到Web服务器时,它总是说“打开失败:ENOENT(没有这样的文件或目录)”

该文件的uri为:“ / content:/ media / external / images / media / 667”

事实:

>我确定文件在那里,因为我可以查看它

>我启用了内部存储读/写,外部存储读/写权限

>使用Galaxy Tab 2 10.1

>没有SD卡

>带有SD卡的Experia Neo V可以使用相同的代码(是因为它没有SD卡?)

>尝试在启动应用程序之前拔下电线

>系留USB已关闭

这是代码:

protected Void doInBackground(Void... params) {

// TODO Auto-generated method stub

InspectionsDbController db = new InspectionsDbController(getActivity());

InspectionItemStruct[] ins = db.getInspectionList(((MyApplication)((Activity) mContext).getApplication()).getCurrentInspectionId());

SharedPreferences settings = mContext.getSharedPreferences(MainActivity.PREFS_NAME, 0);

long userId = settings.getLong("userId", 0);

String token = settings.getString("token", "");

for (int i = 0; i < ins.length; i++) {

HttpClient httpClient = new DefaultHttpClient();

HttpContext localContext = new BasicHttpContext();

HttpPost httpPost = new HttpPost("http://webprojectupdates.com/mmp/api/mobile/upload_inspection");

MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

// add userId

try {

entity.addPart("userId", new StringBody(String.valueOf(userId)));

entity.addPart("token", new StringBody(String.valueOf(token)));

} catch (IOException e) {

Log.e("MMP","Error in adding token: "+e.getMessage());

}

// add media attachments

if(ins[i].image!=null){

//Bitmap image = BitmapFactory.decodeFile(ins[i].image);

//ByteArrayOutputStream bos = new ByteArrayOutputStream();

//image.compress(CompressFormat.JPEG, 75, bos);

//byte[] imageData = bos.toByteArray();

//ByteArrayBody bab = new ByteArrayBody(imageData,"image/jpg", ins[i].itemId+".jpg");

//entity.addPart("image", bab);

entity.addPart("image", new FileBody(new File (ins[i].image)));

}

if(ins[i].video!=null){

entity.addPart("video", new FileBody(new File (ins[i].video)));

}

// Normal string data

try {

entity.addPart("itemId", new StringBody(String.valueOf(ins[i].itemId)));

entity.addPart("isExist", new StringBody(String.valueOf(ins[i].itemExists)));

if(ins[i].comments!=null) entity.addPart("comment", new StringBody(String.valueOf(ins[i].comments)));

entity.addPart("condition", new StringBody(String.valueOf(ins[i].condition)));

} catch (IOException e) {

Log.e("MMP","Error in adding inspection data: "+e.getMessage());

}

try {

httpPost.setEntity(entity);

HttpResponse response = httpClient.execute(httpPost, localContext);

String result = EntityUtils.toString(response.getEntity());

} catch (IOException e) {

Log.e("MMP","Error in handling result: "+e.getMessage());

}

publishProgress(i+1,ins.length);

}

return null;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值