![](/img/trans.png)
[英]How to Set image from Camera upload folder of dropbox to ImageView in android?
[英]android - how to upload an image to dropbox?
我正在使用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) {}
}
}
有人知道代码是否有问题吗?
您是否在xml文件中添加了权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.