Skip to content

Instantly share code, notes, and snippets.

@whitemx
Created December 9, 2014 16:40
Show Gist options
  • Save whitemx/9f5515755b8d26f59089 to your computer and use it in GitHub Desktop.
Save whitemx/9f5515755b8d26f59089 to your computer and use it in GitHub Desktop.
LDC Via PUT new document
function saveNewDocument() {
var data = {};
data.__form = "MainTopic";
data.Body = {
"type": "multipart",
"content": [{
"contentType": "text/plain; charset=UTF-8",
"data": "<p>Some HTML content</p>"
}]
};
data.Subject = "This is a subject";
data.__created = new Date().toISOString();
data.__modified = new Date().toISOString();
var fileInput = $("#fileupload");
var file = fileInput[0].files[0];
var reader = new FileReader();
if (file) {
reader.onload = function(e) {
data.Body.content.push({
"contentType": file.type + "; name=\"" + file.name + "\"",
"contentDisposition": "attachment; filename=\"" + file.name + "\"",
"contentTransferEncoding": "base64",
"data": reader.result.match(/,(.*)$/)[1]
});
sendNewMainTopic(data);
}
reader.readAsDataURL(file);
} else {
sendNewMainTopic(data);
}
}
function sendNewMainTopic (data) {
var unid = new Date().getTime();
$.ajax({
dataType: 'json',
type: 'PUT',
headers: {
'apikey': apikey
},
data: data,
url: '/1.0/document/' + dbname + "/MainTopic/" + unid,
complete: function(res) {
console.log(res);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment