嗨,我尝试将文件上传到我的 backendless rest api..但我无法取得好的结果。看来我无法读取文件。代码有什么问题?
Logcat 上的错误响应
02-25 21:03:02.138 31815-31815/com.bloxofcode.backendless I/Error: Server reported an error - cannot read the file.
这是示例代码..
public void OnClick_Upload(View v) {
// create a file locally so there is something to upload
String filename = "myhelloworld-async.txt";
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(filename);
fileOutputStream.write("Hello mbaas!\nUploading files is easy!".getBytes());
fileOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
final File file = new File(filename);
Log.i("FileStream",file.getPath());
// now upload the file
backend.Files.upload( file, "/media", new AsyncCallback<BackendlessFile>()
{
@Override
public void handleResponse( BackendlessFile uploadedFile )
{
Log.i("Output","File has been uploaded. File URL is - " + uploadedFile.getFileURL());
//System.out.println( "File has been uploaded. File URL is - " + uploadedFile.getFileURL() );
//file.delete();
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
Log.i("Error","Server reported an error - " + backendlessFault.getMessage() );
//System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
}
} );
}