我正在使用 Dropbox api,但不知道如何上传图片,即使我浏览图片时,我也会不断收到未找到文件的异常。
我得到这样的图片网址(我使用浏览方法来查找图片,所以图片肯定存在)这里 uri.getPath() 是图片的路径,例如:“/external/images/media/ 536"
protected void photoToPostChosen(Uri uri){
Uri photoUri = uri;
String id = photoUri.getLastPathSegment();
if(null != id){
//Bitmap thumbBitmap = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), Long.parseLong(id), MediaStore.Images.Thumbnails.MICRO_KIND, null);
EditText imagetextbox = (EditText) findViewById(R.id.UI_txt_image_name);
imagetextbox.setText(uri.getPath());
}
}
然后我使用此代码将其上传到保管箱,但它一直给我找不到文件。
// Uploading content.
mySharedPreferences = getSharedPreferences("User_info_file", MODE_PRIVATE);
String imgpath = mySharedPreferences.getString("TEXT_IMAGELOCATION_KEY", "test");
FileInputStream inputStream = null;
try {
Uri path = Uri.parse(imgpath);
File file = new File(path.toString());
inputStream = new FileInputStream(file);
Entry newEntry = mDBApi.putFile("/testing.txt", inputStream,
file.length(), null, null);
Log.i("DbExampleLog", "The uploaded file's rev is: " + newEntry.rev);
} catch (DropboxUnlinkedException e) {
// User has unlinked, ask them to link again here.
Log.e("DbExampleLog", "User has unlinked.");
} catch (DropboxException e) {
Log.e("DbExampleLog", "Something went wrong while uploading.");
} catch (FileNotFoundException e) {
Log.e("DbExampleLog", "File not found.");
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {}
}
}
有谁知道代码是否有问题?