Parse - How to insert data on parse server using REST Api using javascript? - rest

I am integrating parse rest api to insert data on a table using jsp page. and using following code in javascript -
var headers = {
"X-Parse-Application-Id" : "myparseappid",
"X-Parse-REST-API-Key" : "myparserestapi"
};
// Variable to store data:
var userData = {
"name" : "anyname"
};
var data = JSON.stringify(userData);
// Send data:
$.ajax({
type : "POST",
url : "https://api.parse.com/1/classes/MyClassName",
data : userData,
contentType : "application/json",
headers : headers,
dataType:"json",
success : function(data, status, xhr) {
alert("data:" + JSON.stringify(data) + " status: "+ status);
if (status === "success") {
// Show success feedback:
alert("Data was saved successfully");
} else {
// Show error message:
alert("Your data didn't save. Please check that you are online. Status: "
+ status);
}
},
error : function(data, status, xhr) {
// Show error message:
alert("Your data didn't save. Please check that you are online. Status: "
+ status);
}
});
and for ajax i called following js -
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
Question - It is not saving the records whats wrong with above code. please suggest me?
Thanks in advance!

Related

protractor promises - querying an API using "request"

I am trying to use protractor to call an api - it will return some JSON to me and I want to assert against it. I thought I had this working, until I tried to take it further and realised I hadn't got it right, but having a bit of a time trying to work out why.
I have placed some console.logs in and expected the sequence to be 1,2,3 however it appears to be 3 (test finished) then 2 and 1. So I suspect a promise issue.
code below:
'use strict';
var request = require('request');
var path = require('path');
var info;
//var fname = null;
var fname = 'joe';
describe("Sample test", function() {
var request = require('request');
var options = {
method: 'GET',
url: 'URL here',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: '{ "pay_load": [] }'
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
info = JSON.parse(body);
console.log('in the callback now');
//console.log('body :' + body);
//var count = Object.keys(info).length;
//console.log('body len:' + count);
//console.log('info :' + info);
fname = info.firstname;
console.log('firstname1 : ' + info.firstname);
console.log('firstname2 : ' + fname);
} else {
console.log('there was some error');
}
}
it("proves the API is alive - firstname is null", function() {
request(options, callback);
//expect(fname).toBe(null);
console.log('firstname3 : ' + fname);
//expect(fname).toBe(null);
//var common = new Common();
//common.checkForAPI();
});
So in my head I thought I would see "in the callback", then "firstname1", "firstname2" and finally "firstname3"
No, firstname3 will always get printed first, the way you have it. The reason for it as that all http requests in nodejs are async, so while your request is processing (or in flight), firstname3 will be printed. Then console.logs in your request callback.
Edit1 - Addressing the comment
Simple example which would print firstname1,2,3 in sequence (tested)
var request = function(cb) {
//basically call your request stuff and then when you are done call cb
console.log('firstname 1');
console.log('firstname 2');
cb();
};
request(function() {
console.log('firstname 3');
});
This prints
firstname 1
firstname 2
firstname 3
Or you can use a third party library called async and use async.tryEach to run tasks in series.
async.tryEach([
function getDataFromFirstWebsite(callback) {
// Try getting the data from the first website
callback(err, data);
},
function getDataFromSecondWebsite(callback) {
// First website failed,
// Try getting the data from the backup website
callback(err, data);
}
],
// optional callback
function(err, results) {
Now do something with the data.
});

Google Cloud Storage File Upload - Requested page not found. [404]

I am trying to upload a file to Google Cloud Storage using Json API. I am posting the request to below url with the file attachment.
https://www.googleapis.com/upload/storage/v1/b/mybucket/o?uploadType=media&name=solarsystemlrg.png
But I am getting Requested page not found. [404] Error. When I use the below Url, I am able to list the images stored in the bucket (Just to be sure that there are no access issues and bucket name is correct).
https://www.googleapis.com/storage/v1/b/mybucket/o
I have set the headers.
'Authorization' :'Bearer ' + accessToken,
'Content-Type' : contentType,
'Content-Length' : inputFile.size
Please find the code snippet below.
$.ajax({
url: targetUrl,
headers: reqHeaders,
type: 'POST',
data: reqFormWithDataFile,
async: false,
cache: false,
dataType: 'jsonp',
useDefaultXhrHeader: false,
processData: false,
success: function (response) {
alert('File Upload Successful');
},
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
alert(msg);
}
});
Do I need to use a different URL? Or is there any other setting required? Please help.
That's the right URL, so long as you replace mybucket with your actual bucket name. After reading through jquery.ajax(), I emulated what I think is the behavior by adding &callback=foo, due to dataType: 'jsonp' and &_=1474410231688 because cache: false, and issued the request via curl and that produced a valid object with a valid callback. Can you log the entire jqXHR to see more of the status?

How send string/image base64 to Sailsjs - Skipper with ajax

Currently I am capturing the image of the camera, this Base64 format,and I'm sending through ajax.
xhr({
uri: 'http://localhost:1337/file/upload',
method: 'post',
body:'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAA...'
}
0 file(s) uploaded successfully!
Here is a nice link that will guide you to do send an image from an Ajax Client to an ajax server.
http://www.nickdesteffen.com/blog/file-uploading-over-ajax-using-html5
You can read this sails documentation to receive files on a sails server :
http://sailsjs.org/documentation/reference/request-req/req-file
You can do as the following example :
Client side ( ajax ):
var files = [];
$("input[type=file]").change(function(event) {
$.each(event.target.files, function(index, file) {
var reader = new FileReader();
reader.onload = function(event) {
object = {};
object.filename = file.name;
object.data = event.target.result;
files.push(object);
};
reader.readAsDataURL(file);
});
});
$("form").submit(function(form) {
$.each(files, function(index, file) {
$.ajax({url: "/ajax-upload",
type: 'POST',
data: {filename: file.filename, data: file.data}, // file.data is your base 64
success: function(data, status, xhr) {}
});
});
files = [];
form.preventDefault();
});
Server side ( sails ) :
[let's say you have a model Picture that take an ID and a URL]
[here is a sample of Picture controller, just to give you an idea]
module.exports = {
uploadPicture: function(req, res) {
req.file('picture').upload({
// don't allow the total upload size to exceed ~10MB
maxBytes: 10000000
},
function onDone(err, uploadedFiles) {
if (err) {
return res.negotiate(err);
}
// If no files were uploaded, respond with an error.
if (uploadedFiles.length === 0){
return res.badRequest('No file was uploaded');
}
// Save the "fd" and the url where the avatar for a user can be accessed
Picture
.update(777, { // give real ID
// Generate a unique URL where the avatar can be downloaded.
pictureURL: require('util').format('%s/user/pictures/%s', sails.getBaseUrl(), 777), // GIVE REAL ID
// Grab the first file and use it's `fd` (file descriptor)
pictureFD: uploadedFiles[0].fd
})
.exec(function (err){
if (err) return res.negotiate(err);
return res.ok();
});
});
}
};
Hope this will help in your research.
I also recommand you to use Postman to test your API first, then code your client.

Photo upload with facebook-node-sdk Module / (#324) Requires upload file

I'm trying to send a photo using facebook node sdk module to a page. https://github.com/Thuzi/facebook-node-sdk/
I'm able to post to the page wall or to uplaod from an url. But i have a problem trying to uplaod photo from data.
That is how i connected :
FB.api('oauth/access_token', {
client_id: clientid,
client_secret: clientsecret,
redirect_uri: redirecturi,
code: code,
scope: scope,
fileUpload : true,
}, function (resf) { ...}
I get the good access token like this :
FB.api('/me/accounts', function (resf) {
if (!resf || resf.error) {
console.log(!resf ? 'error occurred' : resf.error);
return;
}
for (var i = 0; i < resf.data.length; i++) {
if (resf.data[i].id == pageid)
{
resf.data[i]. access_token
}
});
And i try to upload the photo :
var buff = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBg8SEBQQEBQUEBQUFRQVERYUFhMYGBYVFBUVFBUVEhQYHCYgFxkkGhUVHy8gIycpLSwuFR4xNTAqNSYtLCkBCQoKDgwOFw8PFzUcHSQwKS01NTUsNTUpNS8sNCwsKS4pNDUuLTUsLC8pLCwpNTUvNSkpNSkvLCwsKikpKSksNv/AABEIAK8BHwMBIgACEQEDEQH/xAAcAAEAAgIDAQAAAAAAAAAAAAAABwgFBgEDBAL/xABKEAABAwICBgYECgULBQAAAAABAAIDBBEFIQYHEjFBcRMiUWGBsTI0kaEjQlJyc3SCkrKzCBQkYsEVFhczNVNUVZPR0mODoqPC/8QAGwEBAQADAQEBAAAAAAAAAAAAAAECAwUEBgf/xAAoEQEAAgIBAwIFBQAAAAAAAAAAAQIDEQQFEiExcRMyQZHRUYGh8PH/2gAMAwEAAhEDEQA/AJxREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQdFbWxQxulme2NjRdznk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fqpHc6SIO+6XLz4fJiuDVAnMUlOdzhI09HI2+bXOHVI7wbg7lZ9fEsTXAtcA4HIggEEd4O9F21rQzWHR4iwdG7o5gLvheRtDtLPlt7x42W0LS8Z1SYXO7pGRupJL3D6Z3R2Pbs+jfkAviDR3HafqwV8VUwbm1kLtrxljNz4ojd1HOu/SCOLDzS3HSVLmgN4iNjg97j3XaB4r21Q0ocNln8mxfvt6ckd4Drj3LVX6kq+pmM+IVzXvd6RY1z3ZbgC7ZDQOwCyCG1J+rbVLLUPbVVzDHALOZE4EOm4jaG9sfPN3LNSRozqrw2iIe2Pp5Rukms4g9rG22W8wL963BF24a0AWGQG5coiIIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiIP/Z";
var body = 'My firstdfsfsfd';
FB.api(pageid + '/photos', 'post', { message: body, source: buff, }, function (resf) {
if (!resf || resf.error) {
console.log(!resf ? 'error occurred' : resf.error);
return;
}
console.log( resf);
res.send(resf);
});
And i have this error :
{
"error": {
"message": "(#324) Requires upload file",
"type": "OAuthException",
"code": 324
}
}
This call is working :
var body = 'My firstdfsfsfd';
FB.api(pageid + '/photos', 'post', { message: body, url: 'url_image', }, function (resf) {
if (!resf || resf.error) {
console.log(!resf ? 'error occurred' : resf.error);
return;
}
console.log( resf);
res.send(resf);
});
What did i forget ?
Does multipart upload is allowing with this module : https://github.com/Thuzi/facebook-node-sdk/
It does not appear to support multipart. You could do it manually with the request module:
var request = require('request');
// ....
var access_token = 'abc123',
pageid = 'me',
fburl = 'https://graph.facebook.com/'
+ pageid
+ '/photos?access_token='
+ access_token,
req,
form;
req = request.post(fburl, function(err, res, body) {
if (err)
return console.error('Upload failed:', err);
console.log('Upload successful! Server responded with:', body);
});
form = req.form()
// append a normal literal text field ...
form.append('message', 'My photo!');
// append a file field by streaming a file from disk ...
form.append('source', fs.createReadStream(path.join(__dirname, 'photo.jpg')));
// or append a Buffer ...
form.append('source', someBuffer);
// or append the contents of a remote url ...
form.append('source', request('http://google.com/doodle.png'));
Example (from mscdex) above works for:
form.append('source', requestLib('<imageURL>'));
Gives response:
{"id":"756317401077924","post_id":"100000990137087_756310827745248"}
Also works for:
form.append('source', fs.createReadStream('<imagepath>'));
Gives response:
{"id":"756328687743462","post_id":"100000990137087_756310827745248"}
This is probably all I need. Thanks mscdex, very helpful. But out of curiosity, when I replaced it with an image buffer:
form.append('source', imageBuffer);
It gives the same error as OP (even when using the same image string as OP):
{"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}}
Why? My guess is Facebook wants a specific format for an encoded image.

IPhone PHONEGAP- Https ajax for datatype - XML

I'm trying to get XML response from a secure https URL using Jquery AJAX call...
I'm getting the following error. Can anyone help me with the issue?
Unauthorized user
Here is my code
$.ajax({
type : "GET",
url : url + "?" + params,
error : function(jqxhr, status, error)
{
alert(status +"....."+error);
},
success : function(data, textStatus, jqxhr) {
var xmlDoc = jqxhr.responseText;
alert(xmlDoc);
}
});
Definitely need more details, but if you're sending a request to a secure url, you likely need to pass some kind of value to show you're logged in or some-such, like a cookie value. To pass a value, you may need to use the headers option:
$.ajax({
type : "GET",
url : url + "?" + params,
headers : {"COOKIE", "userID=h3j5o273h4"},
error : function(jqxhr, status, error)
{
alert(status +"....."+error);
},
success : function(data, textStatus, jqxhr) {
var xmlDoc = jqxhr.responseText;
alert(xmlDoc);
}
});