Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
3pia
VISPA
VISPA web
Commits
9cdbbc16
Commit
9cdbbc16
authored
Jul 13, 2013
by
Marcel
Browse files
Implement uploads via base64 encoding.
parent
3a09693f
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
vispa/controller/filesystem.py
View file @
9cdbbc16
...
...
@@ -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,
uploaded
files[]
# Since "
uploaded
files[]" 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
[
'
uploaded
files[]'
]
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"
])
...
...
vispa/extensions/file/static/js/base/base.js
View file @
9cdbbc16
...
...
@@ -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
vispa/extensions/file/static/js/base/items.js
View file @
9cdbbc16
...
...
@@ -135,7 +135,7 @@ var FileBaseMenuItems = Class.extend({
return
{
label
:
'
Download
'
,
alt
:
'
Download
'
,
icon
:
'
ui-icon-arrowthick-1-s
'
,
icon
:
'
ui-icon-arrowthick
stop
-1-s
'
,
callback
:
function
()
{
_this
.
owner
.
actions
.
download
(
data
);
}
...
...
vispa/extensions/file/static/js/extension.js
View file @
9cdbbc16
...
...
@@ -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
);
...
...
vispa/remote/filesystem.py
View file @
9cdbbc16
...
...
@@ -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
...
...
vispa/static/frameworks/jquery/fileupload/jquery.fileupload.js
0 → 100644
View file @
9cdbbc16
This diff is collapsed.
Click to expand it.
vispa/templates/html/sites/index.html
View file @
9cdbbc16
...
...
@@ -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
"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment