I am trying to set up a folder where you can only upload/modify files if you are logged in. The problem is that when I deny access to Write & Remove for NotAuthorisedUser I can no longer upload the file even though I have logged in using the javascript API.
Calling " console.log(Backendless.UserService.getUserRoles()); " says that I am an Authenticated User but when I try to upload the file to the folder, it fails with an error saying I don’t have permission:
“Object {code: 4000, message: “User has no permissions to specified resource”}”
This is what i’ve done so far:
index.html:
<html>
<head>
<title>Test</title>
<script src="libs/jquery.js"></script>
<script src="libs/backendless.js"></script>
</head>
<body>
<input id='fileUploadPicker' type='file' name="files[]" multiple />
<script src="js/app.js"></script>
</body>
</html>
js/app.js:
var APPLICATION_ID = /*AppID*/;
var SECRET_KEY = /*SecretKey*/;
var VERSION = 'v1';
var user;
var files;
if (!APPLICATION_ID || !SECRET_KEY || !VERSION)
alert("Missing application ID and secret key arguments.");
init();
function init() {
Backendless.initApp(APPLICATION_ID, SECRET_KEY, VERSION);
try {
user = Backendless.UserService.login("Admin", "abcd1234" );
if (user != null)
alert("Login successful");
else
alert("Login failed");
}
catch (e) {
alert("Login failed. " + e.message);
}
$("#fileUploadPicker").change(function handleFileSelect(evt){
files = evt.target.files; // FileList object
uploadFile();
});
}
function uploadFile(){
function successCallback(file){
console.log("Uploaded file URL - " + file.fileURL);
}
function errorCallback(e){
console.log(e);
}
var async = new Backendless.Async(successCallback, errorCallback);
console.log(Backendless.UserService.getUserRoles());
Backendless.Files.upload( files, "images", true, async );
}
And the attached file is a screenshot of how i’ve set up the folder permissions and also the console error that I get.
Am I doing something wrong? Am I missing something? Any help is much appreciated!