Hello ,
I was trying to upload a File Using Android SDK , but I get this Error :
Server reported an error - cannot read the file.
My Code is too Basic . I want this to be working in Plain Java because I have to use this Via server Code.
I have used the code exactly from your example docs :
String filename = "test_file.txt";
//Createing a File named post_feed.txt in here
final File file =new File(filename);
file.setReadable(true);
String string = "Hello world!";
FileOutputStream outputStream;
try {
outputStream = new FileOutputStream(file);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
final File lastFile=new File(filename);
lastFile.setReadable(true);
// now upload the file
Backendless.Files.upload( lastFile, "/directory_newsfeed", new AsyncCallback<BackendlessFile>()
{
@Override
public void handleResponse( BackendlessFile uploadedFile )
{
System.out.println( "File has been uploaded. File URL is - " + uploadedFile.getFileURL() );
file.delete();
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
}
} );
Meanwhile , I can easily Upload the File Using Android Context (By Context I mean by using Android Based file Upload) . This perfectly works as :
String filename = "post_feed.txt";
//Createing a File named post_feed.txt in here
final File file = new File(getApplicationContext().getFilesDir(), filename);
String string = "Hello world!";
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
final File lastFile=new File(filename);
// now upload the file
Backendless.Files.upload( file, "/directory_newsfeed", new AsyncCallback<BackendlessFile>()
{
@Override
public void handleResponse( BackendlessFile uploadedFile )
{
System.out.println( "File has been uploaded. File URL is - " + uploadedFile.getFileURL() );
file.delete();
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
}
} );
Edit : I Scanned further through the Stack trace where it gives :
open failed: EROFS (Read-only file system)