1

we are trying to save image in Parse using CloudCode. we followed this link. we are new to javascript,plz guide us...! Thanks in advance.......

var url = file.url();
Parse.Cloud.httpRequest({ url: url }).then(function(response) {
  // Create an Image from the data.
  var image = new Image();
  return image.setData(response.buffer);

}.then(function(image) {
  // Scale the image to a certain size.
  return image.scale({ width: 64, height: 64 });

}.then(function(image) {
  // Get the bytes of the new image.
  return image.data();

}.then(function(buffer) {
  // Save the bytes to a new file.
  var file = new Parse.File("image.jpg", { base64: data.toString("base64"); });
  return file.save();
}); 
we getting error like this

enter image description here

2 Answers 2

1

There's a repeated syntax mistake at the end of each function parameter to then.

The syntax is:

somePromise.then(function() {
    // success
}).then(function() {  // your code says '}.' instead of '}).'
    // success
});

There's an optional error function callback as second param:

somePromise.then(function() {
    // success
}).then(function() {
    // success
}, function(error) {
    // error
});
Sign up to request clarification or add additional context in comments.

Comments

0

You are missing the close parentheses for each promise callback. Your code should be this :

var url = file.url();
Parse.Cloud.httpRequest({ url: url }).then(function(response) {
  // Create an Image from the data.
  var image = new Image();
  return image.setData(response.buffer);

}).then(function(image) {
  // Scale the image to a certain size.
  return image.scale({ width: 64, height: 64 });

}).then(function(image) {
  // Get the bytes of the new image.
  return image.data();

}).then(function(buffer) {
  // Save the bytes to a new file.
  var file = new Parse.File("image.jpg", { base64: data.toString("base64"); });
  return file.save();
}); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.