Reputation: 1468
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?
Upvotes: 4
Views: 1358
Reputation: 1468
Final Update: Good news! A fix has been made and will be released in the next Javascript SDK release 1.6.0.
Upvotes: 6
Reputation: 785
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.
Upvotes: 1