0

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].

animuson
  • 53,861
  • 28
  • 137
  • 147
Tuideapp
  • 11
  • 3

1 Answers1

0

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
    }
  })
}
animuson
  • 53,861
  • 28
  • 137
  • 147
Nawaz Dhandala
  • 2,046
  • 2
  • 17
  • 23
  • I have this imge objet:{name:xx.jpg,localURL:localurl/xx.jpg,type:image/jpeg,lasmodified:null,lasmodifieddate:date,size:1427711,start:0,end:0,fullPath:fullpath.jpg} how i can save this image object, i do not know that: $("#profilePhotoFileUpload")[0]; and fileUploadControl.files[0] ??? how i can create object image File easy?? – Tuideapp Feb 10 '16 at 19:28
  • i traying that: var cloudFile = new CB.CloudFile(new file(foto.fullPath)); // cloudFile.set('name',foto.name); cloudFile.save({ success : function(cloudFile){ alert(cloudFile+" exito"); }, error: function(error){ alert("Error al guardar la img: "+error); } }); //} – Tuideapp Feb 10 '16 at 20:11
  • Which platform are you on? – Nawaz Dhandala Feb 10 '16 at 21:58
  • I have sent this link to our Android Engineer. He'll answer this question very soon. – Nawaz Dhandala Feb 10 '16 at 23:06
  • But is my cel phone android and i am program in javascript with ionic – Tuideapp Feb 10 '16 at 23:09
  • Oh okay, Then you'd use HTML 5 Fule Upload control and pass that object to CloudFile. In that isntance "profilePhotoFileUpload" is the name of your FileUpload Control. – Nawaz Dhandala Feb 10 '16 at 23:16
  • i do not need adjunt file with filupload i have to take a picture with the plugin: $cordovaCapture.captureImage and this return a imageData[0] for later save in cloudboost, this is from devices android. – Tuideapp Feb 11 '16 at 13:32