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

Implement uploads via base64 encoding.

parent 3a09693f
...@@ -6,7 +6,7 @@ import cherrypy ...@@ -6,7 +6,7 @@ import cherrypy
import os import os
import json import json
from vispa.controller import AbstractController from vispa.controller import AbstractController
import xmlrpclib import base64
class FSController(AbstractController): class FSController(AbstractController):
...@@ -167,15 +167,15 @@ class FSAjaxController(AbstractController): ...@@ -167,15 +167,15 @@ class FSAjaxController(AbstractController):
@cherrypy.tools.json_out() @cherrypy.tools.json_out()
def upload(self, *args, **kwargs): def upload(self, *args, **kwargs):
# the html5 uploader provides following kwargs: # the html5 uploader provides following kwargs:
# index, type, name, size, uploadedfiles[] # index, type, name, size, files[]
# Since "uploadedfiles[]" ends with "[]"-brackets # Since "files[]" ends with "[]"-brackets
# we have to use kwargs instead of args # we have to use kwargs instead of args
try: try:
# extract the path # extract the path
path = str(kwargs['path']) path = str(kwargs['path'])
# prepare the parts # prepare the parts
parts = kwargs['uploadedfiles[]'] parts = kwargs['files[]']
# force parrts to be a list # force parrts to be a list
if not isinstance(parts, list): if not isinstance(parts, list):
parts = [parts] parts = [parts]
...@@ -184,7 +184,7 @@ class FSAjaxController(AbstractController): ...@@ -184,7 +184,7 @@ class FSAjaxController(AbstractController):
self.handleUpload(path, parts) self.handleUpload(path, parts)
return self.success() return self.success()
except Exception, e: except Exception as e:
return self.fail(msg='Couldn\'t upload the file(s): %s' % str(e)) return self.fail(msg='Couldn\'t upload the file(s): %s' % str(e))
def handleUpload(self, path, parts): def handleUpload(self, path, parts):
...@@ -202,7 +202,7 @@ class FSAjaxController(AbstractController): ...@@ -202,7 +202,7 @@ class FSAjaxController(AbstractController):
'The file extension \'%s\' is not supported by this server' % ext) 'The file extension \'%s\' is not supported by this server' % ext)
# save the content using the fs # 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.expose
@cherrypy.tools.allow(methods=["POST"]) @cherrypy.tools.allow(methods=["POST"])
......
...@@ -69,6 +69,36 @@ var FileBase = Class.extend({ ...@@ -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({ ...@@ -135,7 +135,7 @@ var FileBaseMenuItems = Class.extend({
return { return {
label: 'Download', label: 'Download',
alt: 'Download', alt: 'Download',
icon: 'ui-icon-arrowthick-1-s', icon: 'ui-icon-arrowthickstop-1-s',
callback: function() { callback: function() {
_this.owner.actions.download(data); _this.owner.actions.download(data);
} }
......
...@@ -103,6 +103,12 @@ var FileBrowserContent = ExtensionContentFull.extend({ ...@@ -103,6 +103,12 @@ var FileBrowserContent = ExtensionContentFull.extend({
callback: function() { callback: function() {
_this.browser.updateView(); _this.browser.updateView();
} }
}, {
label: "Upload",
icon: "ui-icon-arrowthickstop-1-n",
callback: function() {
_this.browser.upload();
}
}]; }];
this.browser = new FileBrowser(this, path); this.browser = new FileBrowser(this, path);
......
...@@ -10,7 +10,7 @@ from mimetypes import guess_type ...@@ -10,7 +10,7 @@ from mimetypes import guess_type
from zipfile import ZipFile from zipfile import ZipFile
import json import json
import stat import stat
import base64
class FileSystem(object): class FileSystem(object):
...@@ -275,7 +275,7 @@ class FileSystem(object): ...@@ -275,7 +275,7 @@ class FileSystem(object):
if os.path.exists(path) and not force: if os.path.exists(path) and not force:
return False return False
out = open(path, "wb") out = open(path, "wb")
out.write(content) out.write(base64.b64decode(content))
out.close() out.close()
return True return True
......
This diff is collapsed.
...@@ -60,7 +60,8 @@ ...@@ -60,7 +60,8 @@
"resizablesnap/jquery.ui.resizable.snap.ext.min.js", "resizablesnap/jquery.ui.resizable.snap.ext.min.js",
"isotope/jquery.isotope.min.js", "isotope/jquery.isotope.min.js",
"transparency/jquery.transparency.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", framework_scripts = ["class/class.min.js",
"json/json2.js", "json/json2.js",
#"bootstrap/js/bootstrap.min.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