Page 2 of 3

delete file from appery database via service

Posted: Tue Jul 23, 2013 9:54 pm
by Sean Kelley

there is nothing to scroll

there was never a tackFile collection in the DB to my knowledge. There was only 'tack' database with 'text' collection that I used to store related info about files that were uploaded which are still there in the Files tab.


delete file from appery database via service

Posted: Wed Jul 24, 2013 7:59 am
by Kateryna Grynko

Hi Sean,

To delete file create a simple REST Service with parameters object (probably tack_settings) as Settings. Add the following headers:
X-Appery-Database-Id: {database_id}
X-Appery-Session-Token: from localStorage (maybe!)

As an address use "https://api.appery.io/rest/1/db/files..."
and set DELETE request method.


delete file from appery database via service

Posted: Fri Jul 26, 2013 4:01 pm
by Sean Kelley

Hi
Thanks for the help so far. I have have been able to delete a file if the creator deletes, but I still need to understand how to give an admin account delete permission.
Reading this:
http://docs.appery.io/documentation/b...

leads me to believe I need to explicitly set permissions on each file when creating it to include the admin account id in the acl list of file if I want to give that user delete capability. Is that correct?

Right now, I have test file with acl of (get created automatically after sign in and following code):
{"*":{"read":true},"51f275d7e4b0c2d8935a62ee":{"read":true,"write":true}}

If I want to add another user id with delete permission how do I do that? I am specifically thinking of uploading files via ajax/javascript like so:
code
var serverUrl = 'https://api.appery.io/rest/1/db/files/' + file.name;
$.canvasResize(file, {
width: 300,
height: 0,
crop: false,
quality: 80,
//rotate: 90,
callback: function(data, width, height) {
$('<img>')&#46;attr('src', data);
var f = dataURItoBlob(data);
$&#46;ajax({
type: "POST",
beforeSend: function(request) {
request&#46;setRequestHeader("X-Appery-Database-Id", tack_settings['database_id']);
request&#46;setRequestHeader("X-Appery-Session-Token", localStorage&#46;getItem('token'));
request&#46;setRequestHeader("Content-Type", 'image&#47;jpeg');
},
url: serverUrl,
data: f,
processData: false,
contentType: false,
success: function(data) {
alert("success");
localStorage&#46;setItem('image_url', data&#46;fileurl);
createAd&#46;execute( {} );
},
error: function(data) {
alert('there was a problem saving your photo');}
});
}
/code

I understand I can use a master key in a "trusted" environment but I am guessing that that does not mean a public web site.


delete file from appery database via service

Posted: Fri Jul 26, 2013 7:30 pm
by Maryna Brodina

Hello! We would need to check that with dev team. I'll update when have information.


delete file from appery database via service

Posted: Mon Jul 29, 2013 2:02 pm
by Maryna Brodina

Hello! Sorry for late reply. You can't set acl and upload file at the same time. You can upload file first and then update acl. To do that you should run the following request:
codecurl -X PUT \
-H "X-Appery-Database-Id: <databaseID>" \
-H "X-Appery-Session-Token: <userSessionToken>" \
-H "Content-Type: application&#47;json" \
-d '{<user>:{<permissionType>:<boolean>,&#46;&#46;&#46;},&#46;&#46;&#46;}'
https:&#47;&#47;api&#46;appery&#46;io&#47;rest&#47;1&#47;db&#47;files&#47;<fileName>&#47;acl/code
where: is Appery DB user's session token;
is database unique identifier;
is the name of file in DB;
is userId, or " * " for 'public' ACL;
is "read" or "write";


delete file from appery database via service

Posted: Mon Jul 29, 2013 10:44 pm
by Sean Kelley

I am doing something wrong when adding this permission via service call. When I upload the file: Under Files in console, I get the file permissions setup as normal with file name, owner, and public read and owner read/write.

When I then call my service to add permissions to the file for my admin account a new row is added to the files tab. Instead of listing the file name, I get a new name with the .acl extension. The file type is not 'image/jpeg' but rather 'application/json'

I expected to see a modified acl for the file thus having only one row.

The ownership is same and the acl is same:
{"*":{"read":true},"my-user-id":{"read":true,"write":true}}

Image

Here is what my service setup looks like:
Image
Image


delete file from appery database via service

Posted: Mon Jul 29, 2013 10:50 pm
by Sean Kelley

I also do a javascript in mapping to set the userId like so where xxxx... is the admin account id:
x='{"xxxxxxxxxxxxxxxxxxxxx736":{"read":true,"write":true}}';
return x;

I was not sure if this method was correct and also if I should have included the complete acl of * and the file owner. Should permission changes be full replace or an addition to existing.


delete file from appery database via service

Posted: Tue Jul 30, 2013 12:17 am
by Illya Stepanov

Hello Sean - we need to check this. We'll update.


delete file from appery database via service

Posted: Tue Jul 30, 2013 6:29 am
by Maryna Brodina

Hello!
1) there are different names of filename parameter on your screenshots (filename and fileName) that's why file can't be found and new record is added.
2) filename should be the same you receive from Uploading to DB service (with symbols added at the beginning)
3) [quote:]Should permission changes be full replace or an addition to existing[/quote] full replace
4) [quote:]I also do a javascript in mapping to set the userId[/quote] it's not correct. You need to send object only. It means you can't update through services, you should use ajax (as with uploading files). You can use service only if you want to give rights to read and write to everyone - then you can give parameter name * and add in mapping:
codereturn {"read": true, "write": true};/code


delete file from appery database via service

Posted: Fri Aug 02, 2013 8:59 pm
by Kateryna Grynko

Hi Sean,

Marina mentioned request PUT method above. I see you use POST. Please try using PUT method.