Created
December 9, 2014 16:40
-
-
Save whitemx/9f5515755b8d26f59089 to your computer and use it in GitHub Desktop.
LDC Via PUT new document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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