Uploads
Rexpense uses Amazon S3 to store all user's uploads. The process is very simple: first you have to request all the necessary informations in Rexpense API; then you have to send the file to Amazon S3. As a response, you'll receive an URL of the file.
Allowed file extentions
image/jpeg
image/jpg
image/gif
image/png
image/tiff
application/pdf
application/xml
text/xml
New upload
Requests the necessary informations to the Rexpense API. To find out what to do with these informations, see the Example section.
Definition
GET https://app.rexpense.com/api/v1/uploads/new
Example Request
$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/uploads/new \ -H 'Accept: application/json' \ -H 'Content-type: application/json'
Response Example
Example
In this section, we'll walk through all the steps necessary to upload to Amazon S3.
Request credentials in Rexpense API
The first step is to require the informations to the Rexpense API. These informations are required to upload the file to Amazon S3. Without them, it'll not be possible to upload the file.
You have to use the key
parameter provided by the Rexpense API to build the path using the filename.
The key you will provide to Amazon S3 must starts with this key, otherwise you won't be able
to send the file.
The expiration
parameter provides the time in UTC of when this credential information
will expire. After this time, you will have to request another information in the Rexpense API.
Request Example
$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/uploads/new \ -H 'Accept: application/json' \ -H 'Content-type: application/json'
Response Example
Upload file to Amazon S3
After getting the informations, you have to send a POST request to the host with the following parameters (remember, the order of the parameters is very important):
key: | string |
acl: | string 'private' |
AWSAccessKeyId: | string |
policy: | string |
signature: | string |
success_action_status: | string '201' |
content-type | string content-type of the file |
file: |
string file as Base64 |
As a response, you'll receive a XML containing the URL of the file and other informations. This is the URL you'll use to attach a file to a Expense, for example.
Request Example
$ curl https://rexpense-direct-uploads.s3.amazonaws.com/ \ -F "key=uploads/1/my-filename.png" \ -F "acl=private" \ -F "AWSAccessKeyId=AKIAJW7YQQVLAM5O3CAQ" \ -F "policy=eyJleHBpcmF0aW9uIjoiMjAxNC0wNi0xN1QyMzoxOTo1MVoiLCJjbIjIwMSJ9XX0=" \ -F "signature=cWtBq+gNnDPaHC6yfpBb+Uh2yak=" \ -F "success_action_status=201" \ -F "content-type=image/png" \ -F "file=@image.png"