繁体   English   中英

Parse.com文件数组

[英]Parse.com array of files

我正在将图像上传到Parse.com,并在成功的响应中返回了文件名(生成)和文件URL。 这对于单个关联来说很好,但是我的一个类需要为一个条目包含多个文件。

当前正在尝试创建一个Pointers / File引用数组,以便它们在数据浏览器中显示为蓝色按钮。 问题在于它不会创建这些蓝色按钮,而只是将对象按原样扔到数组中。

    $scope.saveCreatedExercise = function(exercise) {
        imageStore = []
        for (var i = 0; i < exercise.images.length; i++) {

            var data = {
                "__type": "File",
                "name": exercise.images[i]._name
            }
            imageStore.push(data);
        };

        ParseFactory.provider('ClientExercises/').create({
            exerciseDescription: exercise.exerciseDescription,
            exerciseName: exercise.exerciseName,
            user: {
                "__type": "Pointer",
                "className": "_User",
                "objectId": Parse.User.current().id
            },
            images: imageStore

        }).success(function(data) {
            $state.go('app.exercises', {
                loadProgramme: data.objectId
            });
        }).error(function(response) {
            errorFactory.checkError(response);
        });

    } 

这甚至有可能实现吗?

问题的症结在于,我希望班级中的一个条目与许多文件相关联。

我有一个可行的解决方案,以防其他人遇到此问题。 此方法的重要性在于,在不保存实际的分析文件对象引用的情况下,使用设置进行文件清理时,将删除所有引用的文件。 此方法可防止清除这些文件

我在实现中使用angularjs和解析javascript sdk。 将ParseFile对象添加到父对象数组字段时,我遇到的问题是JavaScript错误“ Uncaught TypeError:将圆形结构转换为JSON”。

Angular v1.4.4,解析JS v1.5

var parseObject = {{ existing parse object }}
var files = {{ existing array of files base64 encoded }}
var parseFiles = [];
var promises = [];

// loop through the files so first save them to parse cloud 
// (in my case these files were uploaded via ng-file-upload)
angular.forEach(files, function(file,i){
  parseFiles[i] = new Parse.File(file.name,{
    base64: file.dataUrl
  });
  promises.push(parseFiles[i].save());
});

// actually save the files in one batch process of promises
Parse.Promise.when(promises).then(function(){
  // success callback says all files are saved, now lets add them to the parent
  angular.forEach(parseFiles, function(parseFile,i){
    delete parseFile._previousSave; //--> fix circular json error
    parseObject.addUnique('images',parseFile); // could alternatively use .add()
  });
  // now save the parent with the references to the files
  return parseListing.save();
}).then(function(){
  successCallback();
},function(error) {
  errorCallback();
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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