Server reported an error - cannot read the file.

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)

Hello @Pujan Paudel
Your app has no permission to modify files on your device, either choose less restrictive security policy in Android Manifest or upload file using Android Context.
Artur

I would want to do basic CRUD of Files through my Server Code ( Java ) rather than the Android Client . So , I wanted to do with Plain Java .
Isn’t their any way to do it ?
if so , how could I Do it :slight_smile:

You will not encounter such security restrictions using Plain Java. Your code cannot be generic in such case.

@Artur
Okay that`s cool :slight_smile:
What do you mean by 'Your Code cannot be Generic in such case ’ ? Could you give me a slight pointer regarding it .
And ,to add to the question : If I have the Url of the File , Can I do Basic Appending Operation on that File Using Basic File I/O through my Server Code . ( Java operations using Buffered Input Stream Reader and Writer ) . I havent yet experimented it by deploying my code in Server Code , but Did experiment it with Plain Java and could. Only perform read operation , but not the Write Opertions .Did that happen due to security reasons on outside the server code or is this thing actually not possible ?
Regards ,
Pujan

@Pujan
I meant you should have two versions of code - for Android and for Java.

In regard to second question -
You are not be able to access FileSystem in Custom Business Logic.

Artur