机器人 - 如何上传图片到收存箱? [英] android - how to upload an image to dropbox?
问题描述
我使用Dropbox的API,但无法弄清楚如何上传图片,我不断收到文件未发现异常,甚至当我浏览图像。
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.
我得到这样的图像URL(我用的浏览方法找到图像,使画面肯定存在)
这里uri.getPath()是路径图像,看起来像这样的例子:
/外部/图像/媒体/ 536
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());
}
}
然后我用这个code把它上传到Dropbox的,但它一直给我的文件没有找到。
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) {}
}
}
有谁知道,如果事情是错的code?
Does anyone know if something is wrong with the code?
推荐答案
你在XML文件中添加的权限
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"/>
这篇关于机器人 - 如何上传图片到收存箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!