简体   繁体   中英

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

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

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
    }
  })
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM