Save Image jpg, png, jpeg... in a column in CloudBoost backend as a service

195 views Asked by At

I need to save an image file in the column Adjunto, I do not know

var comentario = new CB.CloudObject('Comentarios'); 
comentario.set("IdPersona", new CB.CloudObject("User", "4bD5Gz7Q"));
comentario.set("IdEmpresa", new CB.CloudObject("User", id));
comentario.set("Comentario", coment);
comentario.set("Calificacion", parseInt(calificacion));
comentario.set("Ubicacion", new CB.CloudGeoPoint(gps[0],gps[1]));
comentario.set("Adjunto",function(){


  new CB.CloudFile(foto).set('name',"foto.jpg").save({
    success : function(cloudFile){
      alert(cloudFile.URL);
    }, error: function(error){
      alert("error: "+error);
    }
  });


});
comentario.save({
  success: function(data){

      alert("Exito!");

    }, error: function(error){

      alert("Error: "+error);

      }
    }); 
  }

The param foto is an object $cordovaCapture.captureImage named imageData[0].

1

There are 1 answers

7
Nawaz Dhandala On

You cannot set a function() to a column. That's not valid.

Try this instead :

var fileUploadControl = $("#profilePhotoFileUpload")[0];
if (fileUploadControl.files.length > 0) {
  var file = fileUploadControl.files[0];
  var name = "photo.jpg";
  var cloudFile = new CB.CloudFile(file);
  cloudFile.set('name', name);
  cloudFile.save({
    success: function(cloudFile) {
      //You can now use this cloudFile object to save it in your CloudObject. 
      comentario.set("IdPersona", new CB.CloudObject("User", "4bD5Gz7Q"));
      comentario.set("IdEmpresa", new CB.CloudObject("User", id));
      comentario.set("Comentario", coment);
      comentario.set("Calificacion", parseInt(calificacion));
      comentario.set("Ubicacion", new CB.CloudGeoPoint(gps[0], gps[1]));
      comentario.set("Adjunto", cloudFile);
      comentario.save({
        success: function(data) {

          alert("Exito!");

        },
        error: function(error) {

          alert("Error: " + error);

        }
      });
    },
    error: function(error) {
      //error
    }
  })
}