如何通过JavaScript在Parse.com中保存图像? [英] How to save an Image in Parse.com via JavaScript?

查看:158
本文介绍了如何通过JavaScript在Parse.com中保存图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在其中一个列中添加包含Image的新Object,但它不能保存我的Pic,我的代码中是否有任何错误?特别是保存图像的一部分!!

I wanna add new Object that containing an Image in one of its columns , but it dose not save My Pic , Is there any mistake in my code ? specially part of saving Image !!

我出现问题的JavaScript:

My JavaScript where the problem appeared:

它永远不会上传我的图片解析!!

It never upload my pic in parse !!

    <script type="text/javascript">
    Parse.initialize("key", "key");


   var products = Parse.Object.extend("products");

    var fileUploadControl = $("#profilePhotoFileUpload")[0];
if (fileUploadControl.files.length > 0) {
var file = fileUploadControl.files[0];
var name = "photo.png";

var parseFile = new Parse.File(name, file);
}
parseFile.save().then(function() {
  //The file has been saved to Parse.
   }, function(error) {
   // The file either could not be read, or could not be saved to Parse.
 });

    </script>

这里我添加了html行上传文件:

Here I added html line to upload file:

<input type="file" id="profilePhotoFileUpload">


推荐答案

我得到的答案我可能与你分享有人得到好处

I got the answer I am sharing it with you maybe someone get benefit

上传文件的 THML 行是:

<input type="file" id="pic">

< script> 中的代码在解析中获取并保存图像是:

The code in <script> to get and save image in parse is :

     var fileUploadControl = $("#pic")[0];
   if (fileUploadControl.files.length > 0) {
   var file = fileUploadControl.files[0];
   var name = "photo.png";

   var parseFile = new Parse.File(name, file);

   //put this inside if {
   parseFile.save().then(function() {
   // The file has been saved to Parse.
   }, function(error) {
   // The file either could not be read, or could not be saved to Parse.
    });

    // Be sure of ur parameters name
    // prod is extend of my class in parse from this: var prod = new products();
    prod.set("picture", parseFile);
    prod.save();
   }

这篇关于如何通过JavaScript在Parse.com中保存图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆