简体   繁体   中英

associating an array of photos with a user on parse.com

I'm trying to upload several user photos to parse.com and associate them with a user object. I'm using the javascript sdk https://www.parse.com/docs/js_guide#objects-types I'm able to successfully save the photo as a file object. But when I try to build an array column in the user object/table the sdk errors out.

I get the error JSON.stringify cannot serialize cyclic structures. upon saving the user object.

profileController.js

// uploads photo to rest api given local file_uri
$scope.addPhoto = function() {

  var file = new Parse.File("profile-image.jpeg", { base64: $scope.imageData });
  file.save().then(function(res) {
    console.log('success', res);
    var array = ['foo', file];
    $scope.user.set('photos', array);
    $scope.user.save();
  }, function(error) {
      console.log('error', error);
  });
};

This error arises when the object being serialized holds references to itself. My question then is - Is there a way to associate all user image files with a user object on parse.com? Ideally as an array column because I know there will never be more than 5 profile images per user. 文件对象

PictureHolder.Class

 {"photos":["url": $parseFile1, "url":$parseFile2, "url":$parseFile3...]}

_User contains the following pointer column.

{"linkPhotos":{"__type":"Pointer","className":"PictureHolder","objectId":$ID_Pointed_TO}}

flat query on _User table just add following to the Query.parms...

 include=linkPhotos

that will inline into the Json response, the full, linked row from the 2nd table.

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