android.system.ErrnoException:open failed:ENOENT(没有这样的文件或目录)

时间:2015-11-13 09:08:32

标签: android file file-upload

我想使用alexbbb upload service library上传.pdf文件。但我一直在通知栏中收到Error while uploading

logcat的:

W/com.alexbbb.uploadservice.MultipartUploadTask﹕ Error in uploadId e28a7a1b-45af-42f1-a242-db69feba2d43 on attempt 1. Waiting 1s before next attempt
java.io.FileNotFoundException: /document/0A09-1112:Contact n Tort.pdf: open failed: ENOENT (No such file or directory)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)

我的onActivityResult()

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_FILE && resultCode == RESULT_OK && data != null) {
        filePath = data.getData().getPath();
        File file = new File(filePath);
        filePath = file.getAbsolutePath();
        data.putExtra("filePath", filePath);
        choosenFile.setText(data.getStringExtra("filePath"));
    } else {
        Toast.makeText(this, "Error in choosing file",
                Toast.LENGTH_LONG).show();
    }
}
onUploadButtonClick()

中的

private void onUploadButtonClick() {
    final String serverUrlString = "http://XXXX/uploadNotes.php";
    if (filePath.isEmpty()) {
        Log.d(TAG, "filePath is null");
    } else {
        Log.d(TAG, filePath);
    }
    final String fileToUploadPath = filePath;
    final String paramNameString = "uploaded_file";

    String fileName[] = fileToUploadPath.split("/");

    final MultipartUploadRequest request =
            new MultipartUploadRequest(this, UUID.randomUUID().toString(), serverUrlString);

    request.addFileToUpload(fileToUploadPath, paramNameString,
            fileName[fileName.length-1]+".pdf", ContentType.APPLICATION_OCTET_STREAM);

// code.....
}

我已经允许在AndroidManifest中读取和写入外部存储空间的权限,所以可能问题是我使用了不正确的filePath上传。

我该怎么做才能让它有效?

更新:

我使用getAbsolutePath()getAbsoluteFile()getCanonicalPath()getCanonicalFile()getPath(),全部返回/document/0A09-1112:Contact n Tort.pdf

文件名为Contact n Tort.pdf(不知道0A09-1112:是什么)并位于SD卡/文件中

0 个答案:

没有答案