summaryrefslogtreecommitdiff
path: root/frontend/app/api/crud.upload.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/api/crud.upload.js')
-rw-r--r--frontend/app/api/crud.upload.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/frontend/app/api/crud.upload.js b/frontend/app/api/crud.upload.js
index 8c1b265..2837dd4 100644
--- a/frontend/app/api/crud.upload.js
+++ b/frontend/app/api/crud.upload.js
@@ -1,4 +1,5 @@
import { as_type } from 'app/api/crud.types'
+import { session } from 'app/session'
export function crud_upload(type, data, dispatch) {
return new Promise( (resolve, reject) => {
@@ -6,9 +7,17 @@ export function crud_upload(type, data, dispatch) {
const { id } = data
const fd = new FormData()
+ if (!data.tag) {
+ data.tag = 'misc'
+ }
Object.keys(data).forEach(key => {
- if (key !== 'id') {
+ if (key.indexOf('__') !== -1) return
+ if (key === 'id') return
+ const fn_key = `__${key}_filename`
+ if (fn_key in data) {
+ fd.append(key, data[key], data[fn_key])
+ } else {
fd.append(key, data[key])
}
})
@@ -23,12 +32,11 @@ export function crud_upload(type, data, dispatch) {
xhr.addEventListener("error", uploadFailed, false)
xhr.addEventListener("abort", uploadCancelled, false)
xhr.open("POST", url)
+ xhr.setRequestHeader("Authorization", "Bearer " + session.get("access_token"))
xhr.send(fd)
dispatch && dispatch({ type: as_type(type, 'upload_loading')})
- let complete = false
-
function uploadProgress (e) {
if (e.lengthComputable) {
const percent = Math.round(e.loaded * 100 / e.total) || 0