Form POST middleware

To discover whether your Object Storage system supports this feature, see the section called “Discoverability”. Alternatively, check with your service provider.

You can upload objects directly to the Object Storage system from a browser by using the form POST middleware. This middleware uses account secret keys to generate a cryptographic signature for the request. This means that you do not need to send an authentication token in the X-Auth-Token header to perform the request.

The form POST middleware uses the same secret keys as the temporary URL middleware uses. For information about how to set these keys, see the section called “Account secret keys”.

For information about the form POST middleware configuration options, see Form post in the OpenStack Configuration Reference.

 Form POST format

To upload objects to a cluster, you can use an HTML form POST request.

The format of the form POST request is:

 

Example 1.14. Form POST format

<![CDATA[
<form action="SWIFT_URL" (1)
    method="POST" (2)
    enctype="multipart/form-data"> (3)
    <input type="hidden" name="redirect" value="REDIRECT_URL"/> (4)
    <input type="hidden" name="max_file_size" value="BYTES"/> (5)
    <input type="hidden" name="max_file_count" value="COUNT"/> (6)
    <input type="hidden" name="expires" value="UNIX_TIMESTAMP"/> (7)
    <input type="hidden" name="signature" value="HMAC"/> (8)
    <input type="file" name="FILE_NAME(9)"/>
    <br/>
    <input type="submit"/> (10)
</form>
]]&gt;

The example shows these attributes:

1

action="SWIFT_URL"

Set to full URL where the objects are to be uploaded. The names of uploaded files are appended to the specified SWIFT_URL. So, you can upload directly to the root of a container with a URL like:

https://swift-cluster.example.com/v1/my_account/container/

Optionally, you can include an object prefix to separate uploads, such as:

https://swift-cluster.example.com/v1/my_account/container/OBJECT_PREFIX

2

method="POST"

Must be POST.

3

enctype="multipart/form-data"

Must be multipart/form-data.

4

name="redirect" value="REDIRECT_URL"

Redirects the browser to the REDIRECT_URL after the upload completes. The URL has status and message query parameters added to it, which specify the HTTP status code for the upload and an optional error message. The 2nn status code indicates success.

The REDIRECT_URL can be an empty string. If so, the Location response header is not set.

5

name="max_file_size" value="BYTES"

Required. Indicates the size, in bytes, of the maximum single file upload.

6

name="max_file_count" value= "COUNT"

Required. Indicates the maximum number of files that can be uploaded with the form.

7

name="expires" value="UNIX_TIMESTAMP"

The UNIX timestamp that specifies the time before which the form must be submitted before it becomes no longer valid.

8

name="signature" value="HMAC"

The HMAC-SHA1 signature of the form. See the section called “HMAC-SHA1 signature for form POST”.

9

type="file" name="FILE_NAME"

File name of the file to be uploaded. You can include from one to the max_file_count value of files.

The file attributes must appear after the other attributes to be processed correctly.

If attributes appear after the file attributes, they are not sent with the sub-request because all attributes in the file cannot be parsed on the server side unless the whole file is read into memory; the server does not have enough memory to service these requests. Attributes that follow the file attributes are ignored.

10

type= "submit"

Must be submit.

 HMAC-SHA1 signature for form POST

Form POST middleware uses an HMAC-SHA1 cryptographic signature. This signature includes these elements from the form:

The following example code generates a signature for use with form POST:

 

Example 1.15. HMAC-SHA1 signature for form POST

import hmac
from hashlib import sha1
from time import time
path = '/v1/my_account/container/object_prefix'
redirect = 'https://myserver.com/some-page'
max_file_size = 104857600
max_file_count = 10
expires = int(time() + 600)
key = 'MYKEY'
hmac_body = '%s\n%s\n%s\n%s\n%s' % (path, redirect,
max_file_size, max_file_count, expires)
signature = hmac.new(key, hmac_body, sha1).hexdigest()

For more information, see RFC 2104: HMAC: Keyed-Hashing for Message Authentication.

 Form POST example

The following example shows how to submit a form by using a cURL command. In this example, the object prefix is photos/ and the file being uploaded is called flower.jpg.

This example uses the swift-form-signature script to compute the expires and signature values.

$ bin/swift-form-signature /v1/my_account/container/photos/ https://example.com/done.html 5373952000 1 200 MYKEY
Expires: 1390825338
Signature: 35129416ebda2f1a21b3c2b8939850dfc63d8f43
$ curl -i https://swift-cluster.example.com/v1/my_account/container/photos/ -X POST \
       -F max_file_size=5373952000 -F max_file_count=1 -F expires=1390825338 \
       -F signature=35129416ebda2f1a21b3c2b8939850dfc63d8f43 \
       -F redirect=https://example.com/done.html \
       -F [email protected]
Questions? Discuss on ask.openstack.org
Found an error? Report a bug against this page

loading table of contents...