Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving Javascript object that has an array of Parse.files causes "Converting circular structure to JSON" error

I'm running into a problem where parse.com doesn't like it when I try to upload an array of parse files to parse.

I currently have an array (arr) that is filled with base64 string image data

for (var i=0; i<arr.length; i++){
    var pfile = new Parse.File("photo", { base64: arr[i] });
    pfile.save();
    parseArr.push(pfile);
}

When I attempt to save the array to a column called "images" to parse.com data browser, I run into an error:

posts.set("images", parseArr)

I end up with this error

TypeError: Converting circular structure to JSON
    at Object.stringify (native)
    at _.extend._resetCacheForKey (../node_modules/parse/build/parse-latest.js:4957:25)

Is there anyway I can upload multiple photos that will show up in one column in parse.com? Here's an archived section of parse.com's question but they require a change in the source code to circumvent the problem.

Reference to the parse.com archive question forum

Help?

like image 682
Bryan Avatar asked Mar 18 '23 18:03

Bryan


2 Answers

Final Update: Good news! A fix has been made and will be released in the next Javascript SDK release 1.6.0.

BugMe

like image 92
Bryan Avatar answered Apr 06 '23 02:04

Bryan


Before saving the array, I converted each Parse.File into a custom object containing the same attributes as the file, including __type.

var convertedFiles = [];
_.each(files, function (file) {
    var data = { __type = 'File', name: file.name, url: file.url() };
    convertedFiles.push(data);
});
parseObj.set('files', convertedFiles);
parseObj.save();

While a client fetches these converted objects, they interpret each of them as a Parse.File.

like image 20
ajgarn Avatar answered Apr 06 '23 01:04

ajgarn