我正在尝试使用Android应用将文件上传到笔记本电脑上的节点js服务器。虽然它与html工作正常,当在Andorid尝试做同样的事情时,我得到以下错误。 服务器是一个简单的节点服务器,当我使用其他发布文件的方法时似乎工作正常。
Error in upload with ID: 10ff84ba-0768-4423-a955-7a1a4f68d1aa. /init.rc: open failed: EACCES (Permission denied)
java.io.FileNotFoundException: /init.rc: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:456)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at com.alexbbb.uploadservice.BinaryUploadFile.getStream(BinaryUploadFile.java:34)
at com.alexbbb.uploadservice.BinaryUploadTask.writeBody(BinaryUploadTask.java:29)
at com.alexbbb.uploadservice.HttpUploadTask.upload(HttpUploadTask.java:131)
at com.alexbbb.uploadservice.HttpUploadTask.run(HttpUploadTask.java:65)
at com.alexbbb.uploadservice.UploadService.onHandleIntent(UploadService.java:127)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:442)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at com.alexbbb.uploadservice.BinaryUploadFile.getStream(BinaryUploadFile.java:34)
at com.alexbbb.uploadservice.BinaryUploadTask.writeBody(BinaryUploadTask.java:29)
at com.alexbbb.uploadservice.HttpUploadTask.upload(HttpUploadTask.java:131)
at com.alexbbb.uploadservice.HttpUploadTask.run(HttpUploadTask.java:65)
at com.alexbbb.uploadservice.UploadService.onHandleIntent(UploadService.java:127)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
01-01 08:17:17.382 20517-25217/jorc.com.fileupload2 W/com.alexbbb.uploadservice.BinaryUploadTask: Error in uploadId 5d59b0bb-5f5f-4926-b17d-87a8e408af4f on attempt 1. Waiting 1s before next attempt java.io.FileNotFoundException: /init.rc: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:456)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at com.alexbbb.uploadservice.BinaryUploadFile.getStream(BinaryUploadFile.java:34)
at com.alexbbb.uploadservice.BinaryUploadTask.writeBody(BinaryUploadTask.java:29)
at com.alexbbb.uploadservice.HttpUploadTask.upload(HttpUploadTask.java:131)
at com.alexbbb.uploadservice.HttpUploadTask.run(HttpUploadTask.java:65)
at com.alexbbb.uploadservice.UploadService.onHandleIntent(UploadService.java:127)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
稍后尝试我从logcat获得以下确认,但仍然没有文件上传到我的服务器:
01-01 08:57:43.032 1837-1837/jorc.com.fileupload2 I/UploadServiceDemo: Upload with ID 2b47d6b5-7bf6-4cf0-aeec-462b20c40ffd is completed: 200, <!DOCTYPE html>
<html>
<head>
<title>File Uploader</title>
<link href="app.css" rel="stylesheet">
</head>
答案 0 :(得分:1)
好像你正在使用githib的这个repo: https://github.com/alexbbb/android-upload-service 在这种情况下,转到MainActivity.java文件并添加
.addHeader("X-Parse-Application-Id", "your_key")
.addHeader("X-Parse-REST-API-Key", "your_key2")
下
.addHeader("file-name", new File(fileToUploadPath).getName())
您只需将文件上传到parse.com即可。
为了方便设备添加:
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Alert");
alertDialog.setMessage(serverResponseMessage);
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
在此下方显示上传的文件网址。
public void onCompleted(String uploadId, int serverResponseCode, String serverResponseMessage) {
progressBar.setProgress(0);
答案 1 :(得分:0)
显然写在你的logcat
权限被拒绝,你需要在你的清单中给予READ权限。
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />