Use POST instead of PUT for file upload

This commit is contained in:
Jan Philipp Timme 2016-11-18 20:37:36 +01:00
parent a445a7c1d2
commit 296628b21d
Signed by: JPT
GPG Key ID: 5F2C85EC6F3754B7
3 changed files with 6 additions and 6 deletions

View File

@ -62,12 +62,12 @@ class RESTView(object):
buf = infile.read(BLOCKSIZE) buf = infile.read(BLOCKSIZE)
return hasher.hexdigest() return hasher.hexdigest()
@view_config(request_method='PUT') @view_config(request_method='POST')
def put(self): def post(self):
try: try:
# Create a fresh uuid for the new file # Create a fresh uuid for the new file
file_id = str(uuid.uuid4()) file_id = str(uuid.uuid4())
# Use PUT /files to create a new file # Use POST /files to create a new file
input_file = self.request.POST['file'].file input_file = self.request.POST['file'].file
# Write the data into a temporary file # Write the data into a temporary file
temp_file_path = os.path.join(self.path_tmp, '%s' % file_id) + '~' temp_file_path = os.path.join(self.path_tmp, '%s' % file_id) + '~'

View File

@ -13,7 +13,7 @@ $(document).ready(function() {
contentType: false, contentType: false,
processData: false, processData: false,
data: form_data, data: form_data,
type: 'PUT', type: 'POST',
success: function(response_text){ success: function(response_text){
response = $.parseJSON(response_text); response = $.parseJSON(response_text);
displayAttributes = ['uuid', 'key', 'name', 'size', 'create_utc', 'md5', 'sha1', 'sha256']; displayAttributes = ['uuid', 'key', 'name', 'size', 'create_utc', 'md5', 'sha1', 'sha256'];

View File

@ -11,11 +11,11 @@
<h1>Welcome!</h1> <h1>Welcome!</h1>
<p> <p>
This site enables users to upload files for temporary or permanent access. This site enables users to upload files for temporary or permanent access.
Since the PUT method of the API is used to upload files, please enable javascript. Since the POST method of the API is used to upload files, please enable javascript.
</p> </p>
<p> <p>
Use this command to upload a file using curl: Use this command to upload a file using curl:
<pre>curl -X PUT {{ request.route_url('files') }} -F "file=@/path/to/your/file"</pre> <pre>curl -X POST {{ request.route_url('files') }} -F "file=@/path/to/your/file"</pre>
You will get a JSON response containing a bunch of checksums and a <b>key</b>. You will get a JSON response containing a bunch of checksums and a <b>key</b>.
Take good care of it, as <b>the key it is your only way to delete the file later</b>! Take good care of it, as <b>the key it is your only way to delete the file later</b>!
In order to <b>delete</b> a file, use this curl command: In order to <b>delete</b> a file, use this curl command: