MediaProxy upload
This commit is contained in:
parent
39c575b52d
commit
483fdb2643
@ -1,4 +1,5 @@
|
|||||||
import { currentBackend } from '../backends/backend';
|
import { currentBackend } from '../backends/backend';
|
||||||
|
import { getMedia } from '../reducers';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Contant Declarations
|
* Contant Declarations
|
||||||
@ -152,13 +153,15 @@ export function loadEntries(collection) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function persistEntry(collection, entry, mediaFiles) {
|
export function persistEntry(collection, entry) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const backend = currentBackend(state.config);
|
const backend = currentBackend(state.config);
|
||||||
|
const MediaProxies = entry.get('mediaFiles').map(path => getMedia(state, path));
|
||||||
|
|
||||||
dispatch(entryPersisting(collection, entry));
|
dispatch(entryPersisting(collection, entry));
|
||||||
backend.persistEntry(collection, entry, mediaFiles).then(
|
backend.persistEntry(collection, entry, MediaProxies.toJS()).then(
|
||||||
({persistedEntry, persistedMediaFiles}) => {
|
({ persistedEntry, persistedMediaFiles }) => {
|
||||||
dispatch(entryPersisted(persistedEntry, persistedMediaFiles));
|
dispatch(entryPersisted(persistedEntry, persistedMediaFiles));
|
||||||
},
|
},
|
||||||
(error) => dispatch(entryPersistFail(collection, entry, error))
|
(error) => dispatch(entryPersistFail(collection, entry, error))
|
||||||
|
@ -67,7 +67,7 @@ class Backend {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
persistEntry(collection, entryDraft) {
|
persistEntry(collection, entryDraft, MediaFiles) {
|
||||||
const entryData = entryDraft.getIn(['entry', 'data']).toObject();
|
const entryData = entryDraft.getIn(['entry', 'data']).toObject();
|
||||||
const entryObj = {
|
const entryObj = {
|
||||||
path: entryDraft.getIn(['entry', 'path']),
|
path: entryDraft.getIn(['entry', 'path']),
|
||||||
@ -79,8 +79,7 @@ class Backend {
|
|||||||
collection.get('label') + ' “' +
|
collection.get('label') + ' “' +
|
||||||
entryDraft.getIn(['entry', 'data', 'title']) + '”';
|
entryDraft.getIn(['entry', 'data', 'title']) + '”';
|
||||||
|
|
||||||
|
return this.implementation.persistEntry(collection, entryObj, MediaFiles, { commitMessage })
|
||||||
return this.implementation.persistEntry(collection, entryObj, entryDraft.get('mediaFiles').toJS(), { commitMessage })
|
|
||||||
.then(
|
.then(
|
||||||
(response) => ({
|
(response) => ({
|
||||||
persistedEntry: this.entryWithFormat(collection)(response.persistedEntry),
|
persistedEntry: this.entryWithFormat(collection)(response.persistedEntry),
|
||||||
|
@ -20,7 +20,8 @@ MediaProxy.prototype.toBase64 = function() {
|
|||||||
const fr = new FileReader();
|
const fr = new FileReader();
|
||||||
fr.onload = (readerEvt) => {
|
fr.onload = (readerEvt) => {
|
||||||
const binaryString = readerEvt.target.result;
|
const binaryString = readerEvt.target.result;
|
||||||
resolve(btoa(binaryString));
|
|
||||||
|
resolve(binaryString.split('base64,')[1]);
|
||||||
};
|
};
|
||||||
fr.readAsDataURL(this.file);
|
fr.readAsDataURL(this.file);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user