-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NodeJS] Attachment data are written as object #60
Comments
Looks like it is dumping the Buffer as a Node-style Buffer object rather than a Blob, so it will have to be converted. Yes this is a bug; it seems I didn't consider the case of attachments in the browser. |
@chancezeus how did you solve this? |
I have managed to write the following code in the client side to overcome this issue if anyone is interested (bare in mind that it probably has bugs), I'll be writing a workaround in the server side in order to crate a file the var textSplit = text.split('\n');
for (let i = 0; i < textSplit.length; i++) {
if (!textSplit[i].startsWith('{"docs')) {
continue;
}
let jsonText = JSON.parse(textSplit[i]);
for (let doc of jsonText.docs) {
let byteArray = doc._attachments[Object.keys(doc._attachments)[0]].data.data;
let str = btoa(byteArray);
doc._attachments[Object.keys(doc._attachments)[0]].data = str
console.log(doc);
}
textSplit[i] = JSON.stringify(jsonText);
}
text = textSplit.join('\n'); nodejs code: var fs = require("fs");
fs.readFile("./tiles.txt", (err, data) => {
let textSplit = data.toString().split("\n");
for (let i = 0; i < textSplit.length; i++) {
console.log("line: " + i);
if (!textSplit[i].startsWith('{"docs')) {
continue;
}
let jsonText = JSON.parse(textSplit[i]);
for (let doc of jsonText.docs) {
let byteArray = doc._attachments[Object.keys(doc._attachments)[0]].data.data;
let str = new Buffer(byteArray).toString("base64");
doc._attachments[Object.keys(doc._attachments)[0]].data = str
}
textSplit[i] = JSON.stringify(jsonText);
}
text = textSplit.join('\n');
console.log("complete");
fs.writeFile("./tile-converted.txt", text, () => console.log("complete writing"));
}); |
When using this plugin to dump my database to a file, the attachments are written:
Importing this goes wrong in the browser since the browser has no clue how to handle this... Your readme states attachments should be saved as 'base64' encoded data. Is there any way to get this behaviour, since the plugin is broken now as a tool for exporting a prepopulated database (used to debug/develop a cordova app in the browser)...
The text was updated successfully, but these errors were encountered: