Commit 9cdbbc16 authored by Marcel's avatar Marcel
Browse files

Implement uploads via base64 encoding.

parent 3a09693f
......@@ -6,7 +6,7 @@ import cherrypy
import os
import json
from vispa.controller import AbstractController
import xmlrpclib
import base64
class FSController(AbstractController):
......@@ -167,15 +167,15 @@ class FSAjaxController(AbstractController):
@cherrypy.tools.json_out()
def upload(self, *args, **kwargs):
# the html5 uploader provides following kwargs:
# index, type, name, size, uploadedfiles[]
# Since "uploadedfiles[]" ends with "[]"-brackets
# index, type, name, size, files[]
# Since "files[]" ends with "[]"-brackets
# we have to use kwargs instead of args
try:
# extract the path
path = str(kwargs['path'])
# prepare the parts
parts = kwargs['uploadedfiles[]']
parts = kwargs['files[]']
# force parrts to be a list
if not isinstance(parts, list):
parts = [parts]
......@@ -184,7 +184,7 @@ class FSAjaxController(AbstractController):
self.handleUpload(path, parts)
return self.success()
except Exception, e:
except Exception as e:
return self.fail(msg='Couldn\'t upload the file(s): %s' % str(e))
def handleUpload(self, path, parts):
......@@ -202,7 +202,7 @@ class FSAjaxController(AbstractController):
'The file extension \'%s\' is not supported by this server' % ext)
# save the content using the fs
fs.save_file_content(os.path.join(path, name), xmlrpclib.Binary(f), force=True)
fs.save_file_content(os.path.join(path, name), base64.b64encode(f.read()), force=True)
@cherrypy.expose
@cherrypy.tools.allow(methods=["POST"])
......
......@@ -69,6 +69,36 @@ var FileBase = Class.extend({
}
}
});
},
upload: function() {
var self = this;
var msgObject = $.Topic('msg.log').publishBack('info', {
text: 'Uploading ...',
icon: 'ui-icon-arrowthickstop-1-n'
})[0];
var path = this.workflow.path
$('<input />')
.attr({type: 'file', name: 'files[]', 'multiple': true})
.css('display', 'none')
.appendTo('body')
.fileupload({
url: this.urlFormatter('ajax/fs/upload?_wid=' + Vispa.workspaceManager.getWorkspace().id + '&path=' + path),
dataType: 'json',
done: function (e, data) {
msgObject.update({
text: $.Helpers.strFormat('Upload done ({0})!', $.Helpers.bytesToString(data.loaded)),
icon: 'ui-icon-check'
});
self.updateView();
},
fail: function() {
msgObject.update({
text: 'Upload failed!',
icon: 'ui-icon-alert'
});
}
}).trigger('click');
return this;
}
});
\ No newline at end of file
......@@ -135,7 +135,7 @@ var FileBaseMenuItems = Class.extend({
return {
label: 'Download',
alt: 'Download',
icon: 'ui-icon-arrowthick-1-s',
icon: 'ui-icon-arrowthickstop-1-s',
callback: function() {
_this.owner.actions.download(data);
}
......
......@@ -103,6 +103,12 @@ var FileBrowserContent = ExtensionContentFull.extend({
callback: function() {
_this.browser.updateView();
}
}, {
label: "Upload",
icon: "ui-icon-arrowthickstop-1-n",
callback: function() {
_this.browser.upload();
}
}];
this.browser = new FileBrowser(this, path);
......
......@@ -10,7 +10,7 @@ from mimetypes import guess_type
from zipfile import ZipFile
import json
import stat
import base64
class FileSystem(object):
......@@ -275,7 +275,7 @@ class FileSystem(object):
if os.path.exists(path) and not force:
return False
out = open(path, "wb")
out.write(content)
out.write(base64.b64decode(content))
out.close()
return True
......
This diff is collapsed.
......@@ -60,7 +60,8 @@
"resizablesnap/jquery.ui.resizable.snap.ext.min.js",
"isotope/jquery.isotope.min.js",
"transparency/jquery.transparency.min.js",
"lightbox/jquery.lightbox.min.js"]
"lightbox/jquery.lightbox.min.js",
"fileupload/jquery.fileupload.js"]
framework_scripts = ["class/class.min.js",
"json/json2.js",
#"bootstrap/js/bootstrap.min.js"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment