0

我正在使用 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) {}
        }
    }

有谁知道代码是否有问题?

4

1 回答 1

0

你在你的xml文件中添加了权限吗

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
于 2013-04-11T02:10:57.727 回答