android-如何将图像上传到dropbox?
我正在使用dropbox api,但不知道如何上传图像,即使在浏览图像时,我也会不断收到“未找到文件”异常 我得到的图像url是这样的(我使用了一种浏览方法来查找图片,因此图片肯定存在) 此处uri.getPath()是图像的路径,如下所示,例如: “/external/images/media/536” 然后我用这个代码把它上传到dropbox,但它一直给我找不到的文件android-如何将图像上传到dropbox?,android,image,upload,dropbox,Android,Image,Upload,Dropbox,我正在使用dropbox api,但不知道如何上传图像,即使在浏览图像时,我也会不断收到“未找到文件”异常 我得到的图像url是这样的(我使用了一种浏览方法来查找图片,因此图片肯定存在) 此处uri.getPath()是图像的路径,如下所示,例如: “/external/images/media/536” 然后我用这个代码把它上传到dropbox,但它一直给我找不到的文件 // Uploading content. mySharedPreferences = getSharedP
// 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"/>
您最好使用e.printStackTrace()
,而不是Log.e(“DbExampleLog”,“未找到文件”)代码>,它只是告诉你一些错误,而不是根异常。我尝试过,它主要说没有这样的文件或目录,我不理解其他行的文本。所以粘贴异常让人们知道发生了什么
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>