more helpers for uploading
This commit is contained in:
25
code/app.py
25
code/app.py
@@ -196,6 +196,31 @@ def download_zip(name,password = None):
|
||||
attachment_filename = name + ".zip"
|
||||
)
|
||||
|
||||
@app.route('/script/upload/<name>/<password>', methods=['GET'])
|
||||
def script_upload(name = None, password = None):
|
||||
session[name] = password
|
||||
(ok,share) = get_share(name)
|
||||
if not ok:
|
||||
return share
|
||||
if not get_or_none(share,'upload') == True:
|
||||
return "Upload not allowed",400
|
||||
return """#!/bin/bash
|
||||
file_name="$1"
|
||||
base_name=$( basename "$1" )
|
||||
test -f "$file_name" || {
|
||||
echo "Add file as argument"
|
||||
exit 1
|
||||
}
|
||||
CAT=$( which cat )
|
||||
which pv &> /dev/null && CAT=$( which pv )
|
||||
|
||||
$CAT "$file_name" | curl -F "file=@-;filename=${base_name}" %supload/%s/%s
|
||||
"""%(
|
||||
request.url_root,
|
||||
name,
|
||||
password
|
||||
)
|
||||
|
||||
|
||||
def file_stat(filename):
|
||||
s = os.stat(filename)
|
||||
|
||||
@@ -202,12 +202,12 @@ def print_rest_api(shares, config, opts):
|
||||
sys.exit(0)
|
||||
|
||||
print("Link to upload file to the share:")
|
||||
print("curl -F file=@'the_file_name.ext' %s/upload/%s/%s"%(
|
||||
print("\n# curl -F file=@'the_file_name.ext' %s/upload/%s/%s"%(
|
||||
config['public_url'],
|
||||
share['name'],
|
||||
share['pass_hash']
|
||||
))
|
||||
print("cat file_to_send.ext | curl -F file='@-;filename=the_file_name.ext' %s/upload/%s/%s"%(
|
||||
print("or \n\n# curl -s %s/script/upload/%s/%s | bash /dev/stdin file_to_upload.ext"%(
|
||||
config['public_url'],
|
||||
share['name'],
|
||||
share['pass_hash']
|
||||
|
||||
Reference in New Issue
Block a user