javascript - 如何通过 JavaScript 在 Parse.com 中保存图像?

标签 javascript image parse-platform

我想在其列之一中添加包含图像的新对象,但它不保存我的照片,我的代码中是否有任何错误?特别是保存图像的一部分!!

出现问题的我的 JavaScript:

它从不在解析中上传我的照片!!

    <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 行来上传文件:

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

最佳答案

我得到了答案,我正在与你分享,也许有人会受益

THML上传文件的行是:

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

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

     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 - 如何通过 JavaScript 在 Parse.com 中保存图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23463012/

相关文章:

java - 从 URL 获取图像 (Java)

javascript - 页面完全加载时确保 javascript 正在运行的最佳方法是什么?

javascript - 允许用户向您的站点添加自己的 JavaScript 的安全问题?

java - 如何在java中绘制图形并另存为图像

java - 将图像从应用程序发送到网络服务器

ios - PFQueryTableViewController 无限滚动 swift

android - 每次更新创建新行以在 Android 上解析

javascript - 如何在 Parse.com SDK 中循环创建多个对象?

php - 在 PHP 中使用 Post 进行 Ajax 调用

javascript - 获取 JavaScript 函数的内容