I'm trying to perform a POST request containing a picture to a document server via ajax out of my mobile JavaScript application.
My ajax call with the required cmis data looks like the following:
var cmisInfo = {
'objectId': parentFolder,
'cmisaction': 'createDocument',
'propertyId[0]': 'cmis:name',
'propertyValue[0]': filename,
'propertyId[1]': 'cmis:objectTypeId',
'propertyValue[1]': 'cmis:document'
};
$.ajax(rootFolder, {
type: 'POST',
data: cmisInfo,
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', csrfToken);
xhr.setRequestHeader('Authorization', "Basic dXNlcjpwdw==");
}
}).done(function(response) {
console.log("New File ID: " + response.properties["cmis:objectId"].value);
}).fail(function(jqXHR) {
console.log(jqXHR.responseJSON.message);
});
The picture im trying to upload is present as a BASE64
string, fetched with a FileReader
. Lets assume it's saved in the following variable:
var pictureBase64; // containing picture from filesystem in BASE64
My question now is, where to put pictureBase64
as content in my request? I suppose that such an object would be sent along in the data
attribute within the ajax call normally, but in my case the data attribute is already used for the required cmis information. How can I send both?
Any help or hints would be appreciated!