more helpers for uploading

This commit is contained in:
Ville Rantanen
2018-02-13 21:42:02 +02:00
parent 98035cea41
commit 5cec2f2a19
2 changed files with 27 additions and 2 deletions

View File

@@ -196,6 +196,31 @@ def download_zip(name,password = None):
attachment_filename = name + ".zip" 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): def file_stat(filename):
s = os.stat(filename) s = os.stat(filename)

View File

@@ -202,12 +202,12 @@ def print_rest_api(shares, config, opts):
sys.exit(0) sys.exit(0)
print("Link to upload file to the share:") 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'], config['public_url'],
share['name'], share['name'],
share['pass_hash'] 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'], config['public_url'],
share['name'], share['name'],
share['pass_hash'] share['pass_hash']