This commit is contained in:
2020-04-22 15:13:00 +00:00
parent 69d0974215
commit 2f7e507474
3 changed files with 94 additions and 32 deletions

View File

@@ -392,6 +392,47 @@ export default {
handleError("DUPLICATE", error, route, reject);
});
});
},
///////////////////////////////////
// POST FILE ATTACHMENTS
// @param {ayId:objectid, ayType:objectType, files:[array of files]}
//
uploadAttachment(at) {
let that = this;
var files = at.files;
var data = new FormData();
for (var i = 0; i < files.length; i++) {
data.append(files[i].name, files[i]);
}
data.append("AttachToObjectType", at.ayaType);
data.append("AttachToObjectId", at.ayaId);
//-----------------
return new Promise(function postAttachmentToServer(resolve, reject) {
let fetchOptions = {
method: "post",
mode: "cors",
headers: {
Authorization: "Bearer " + window.$gz.store.state.apiToken
},
body: data
};
fetch(that.APIUrl("Attachment"), fetchOptions)
.then(that.status)
.then(that.json)
// eslint-disable-next-line
.then((response) => {
resolve(response);
})
.catch(function handlePostAttachment(error) {
handleError("POSTATTACHMENT", error, route, reject);
});
});
//---------------
}
//new functions above here