Page 2 of 3

jQuery and object database error (storing info in database)

Posted: Fri Jun 21, 2013 8:29 pm
by Kateryna Grynko

Replace
codedata: {"filename": filename},/code
with the following:
codedata: JSON.stringify( {"filename": filename} ),/code


jQuery and object database error (storing info in database)

Posted: Fri Jun 21, 2013 8:47 pm
by Anna G.

Hi Katya,

I replaced the first code with the second and now I get a different error: {"code":"DBSC216","description":"Emptyobjectscan'tbecreated.Pleasespecifyatleastonefield."}.

We also added an alert for the stringify function and it gave us the correct output.

codevar file;
function fileSelectHandler(e) {
var files = e.target.files || e.dataTransfer.files;
file = files[0];
previewFile();
}

function userData(filename) {
alert( JSON.stringify( {"filename": filename} ) );
var url = 'https://api.appery.io/rest/1/db/collections/things/';
$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("X-Appery-Database-Id", "51c1d0bde4b0d0a692ef56b1");
request.setRequestHeader("X-Appery-Session-Token", localStorage.getItem('token')),
request.setRequestHeader("Content-Type", "application/json");
},
url: url,
data: JSON.stringify( {"filename": filename} ),
processData: false,
success: function(html) {
alert("it worked");
},
failure: function(html) {
alert("it didn't work");
}
});
}

function upload() {

Code: Select all

 var serverUrl = 'https://api.appery.io/rest/1/db/files/' + file.name.replace(/ /g, "_"); 

 $.ajax({ 
     type: "POST", 
     beforeSend: function(request) { 
         request.setRequestHeader("X-Appery-Database-Id", "51c1d0bde4b0d0a692ef56b1"), 
         request.setRequestHeader("X-Appery-Session-Token", localStorage.getItem('token')), 
         request.setRequestHeader("Content-Type", file.type); 

     }, 
     url: serverUrl, 
     data: file, 
     processData: false, 
     contentType: false, 
     success: function(html) { 
         // upload successful 
         $(".content").html(html); 
         $('#success').show(); 

         userData(html.filename); 
      }, 
     error: function(html) { 
         // upload unsuccessful 
         $(".content").html(html); 
         $('#error').show(); 

}
});
}

function previewFile() {

Code: Select all

 var previewContainer = $('table[dsid=preview]'); 
 var fileName = $('[name=fileName]'); 
 // make the preview container visible once a file was selected 
 previewContainer.toggle(); 

 // set the file name 
 fileName.text(file.name); 

 // display image in preview container 
 if (file.type.indexOf("image") == 0) { 
     var reader = new FileReader(); 
     reader.onload = function(e) { 
         var image = $('[name=image]'); 
         image.attr('src', e.target.result); 
         $('[class=mobileimage1_div]').show(); 
     } 
     reader.readAsDataURL(file); 
 } 

}/code


jQuery and object database error (storing info in database)

Posted: Mon Jun 24, 2013 2:06 pm
by Anna G.

Is there any way to fix this new error?

Thanks,
Anna


jQuery and object database error (storing info in database)

Posted: Tue Jun 25, 2013 10:24 am
by Anton Artyukh5836028

Hi Anna,

I'm sorry for the delay.

What are you seeing in the alert( JSON.stringify( {"filename": filename} ) );?

Do you have field 'filename' in your collection?


jQuery and object database error (storing info in database)

Posted: Tue Jun 25, 2013 2:13 pm
by Anna G.

Hello Anton,

That's completely fine - I just wanted to make sure the topic didn't get buried!

The alert gives {"filename":"nameoffile.jpg"} with "nameoffile.jpg" being the name of the file in the database.

No, we didn't. We didn't know we had to. But this fixed our error!!! Thank you so much for your help (Anton and Katya)!

Thanks again,
Anna


jQuery and object database error (storing info in database)

Posted: Thu Jan 23, 2014 9:04 am
by Asif

Hi
I am also getting same error
code":DBSC007", "description":"serializationerror

I am trying to access a rest service of Appery form Google Chrome rest client

This is my service url : https://api.appery.io/rest/1/db/colle...

I am providing data base id over there but not the session id because it is not required for a collection.

Pls help!


jQuery and object database error (storing info in database)

Posted: Thu Jan 23, 2014 9:58 am
by Kateryna Grynko

Hi Asif,

Do you try on preview on on service Test tab? Do you use our proxy?


jQuery and object database error (storing info in database)

Posted: Thu Jan 23, 2014 11:07 am
by Asif

Hi Katya,
I tried it on Appery service test tab, it is working fine from there with the same parameters and same settings. I am not using Appery.io proxy


jQuery and object database error (storing info in database)

Posted: Thu Jan 23, 2014 11:10 am
by Asif

when i am doing a GET operation it is working fine from Google chrome rest client, but it is failing when i m selecting POST option


jQuery and object database error (storing info in database)

Posted: Thu Jan 23, 2014 11:45 am
by Kateryna Grynko

Asif,

Please post a screenshot of your Chrome REST client where we can see a request itself.