I am using the dropbox api, but can't figure out how to upload image, i keep getting file not found exception even when i browse for the image.
I get the image url like this ( i used a browse method to find the picture so the picture definitely exists) here uri.getPath() is the path to the image and looks like this for example: "/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());
}
}
then i use this code to upload it to dropbox, but it keeps giving me file not found.
// 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) {}
}
}
Does anyone know if something is wrong with the code?
did you add the permission in your xml file
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.