Mission: FILES MASTER
Task: Upload a file using API
Need help with file upload (Flutter SDK); can’t seem to put ‘file’ in a place where code can find/read it.
Using syntax from File Upload - Backendless SDK for Flutter API Documentation.
Code
ElevatedButton(
onPressed: () async {
String filename = “superfast.html”;
File file = await File(filename).writeAsString(“Hello mbaas!\nUploading files is easy!”);
Backendless.files.upload(file, "mission ").then((response) {
print("File has been uploaded. File URL is - " + response!);
file.delete();
}); // upload
}, // onPressed
Console
E/flutter ( 8594): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot open file, path = ‘superfast.html’ (OS Error: Read-only file system, errno = 30)
If ‘filename’ points to ‘assets/files/superfast.html’ (in assets section of pubspec.yaml and in file menu of project), error return changes to:
E/flutter ( 8594): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot open file, path = ‘assets/files/superfast.html’ (OS Error: No such file or directory, errno = 2)