diff options
Diffstat (limited to 'app/client/api')
| -rw-r--r-- | app/client/api/crud.upload.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/app/client/api/crud.upload.js b/app/client/api/crud.upload.js index f680a74..97b6769 100644 --- a/app/client/api/crud.upload.js +++ b/app/client/api/crud.upload.js @@ -1,12 +1,20 @@ import { as_type } from './crud.types' -export function crud_upload(type, id, fd, dispatch) { +export function crud_upload(type, fd, data, dispatch) { return new Promise( (resolve, reject) => { + const id = data.id + + Object.keys(data).forEach(key => { + if (key !== 'id') { + fd.append(key, data[key]) + } + }) + const xhr = new XMLHttpRequest() xhr.upload.addEventListener("progress", uploadProgress, false) xhr.addEventListener("load", uploadComplete, false) xhr.addEventListener("error", uploadFailed, false) - xhr.addEventListener("abort", uploadCanceled, false) + xhr.addEventListener("abort", uploadCancelled, false) xhr.open("POST", '/' + type + '/' + id + '/upload/') xhr.send(fd) @@ -47,7 +55,7 @@ export function crud_upload(type, id, fd, dispatch) { }) } - uploadFailed = function (evt) { + function uploadFailed (evt) { dispatch && dispatch({ type: as_type(type, 'upload_error'), error: 'upload failed', @@ -55,7 +63,7 @@ export function crud_upload(type, id, fd, dispatch) { }) } - uploadCancelled = function (evt) { + function uploadCancelled (evt) { dispatch && dispatch({ type: as_type(type, 'upload_error'), error: 'upload cancelled', |
