There are several ways of uploading file contents to create file resources. The simplest way is to POST a file descriptor containing the file in base64 encoding.
Method | URL | ||
POST | http://<host>:<port>/jasperserver[-pro]/rest_v2/resources/path/to/folder?<param> | ||
Parameters | Type/Value | Description | |
create | true|false | True by default, and the service will create all parent folders if they don't already exist. When set to false, the folders specified in the URL must all exist, otherwise the service returns an error. | |
Content-Type | Content | ||
application/repository. file+json application/repository. file+xml | A well defined file resource descriptor, as described in Uploading File Resources. The contents of the file are base64 encoded in the content attribute of the descriptor. | ||
Return Value on Success | Typical Return Values on Failure | ||
201 Created – The request was successful and, for confirmation, the response contains the full descriptor of the resource that was just created. | 400 Bad Request – Mismatch between the content-type and the fields or syntax of the actual descriptor. |
You can also create a file resource with a multipart form request.
Method | URL | ||||||||||||||
POST | http://<host>:<port>/jasperserver[-pro]/rest_v2/resources/path/to/folder | ||||||||||||||
Content-Type | Content | ||||||||||||||
multipart/form-data | The request should include the following parameters:
| ||||||||||||||
Return Value on Success | Typical Return Values on Failure | ||||||||||||||
201 Created – The request was successful and, for confirmation, the response contains the full descriptor of the resource that was just created. | 400 Bad Request – Mismatch between the content-type and the fields or syntax of the actual descriptor. |
Another form allows you to create a file resource by direct streaming, without needing to create it first as a descriptor object. In this case, the required fields of the file descriptor are specified in HTTP headers.
Method | URL | ||
POST | http://<host>:<port>/jasperserver[-pro]/rest_v2/resources/path/to/folder?<param> | ||
Options | |||
Content-Description: {fileResourceDescription} Content-Disposition: attachment; filename={fileResourceLabel} | |||
Content-Type | Content | ||
{MIME type} | The MIME type that corresponds to the desired file type. The body then contains the binary data representation of that file format. | ||
Return Value on Success | Typical Return Values on Failure | ||
201 Created – The request was successful and, for confirmation, the response contains the full descriptor of the resource that was just created. | 400 Bad Request – Mismatch between the content-type and the fields or syntax of the actual descriptor. |
When using MIME types, you must specify the MIME type that corresponds with the desired file type, as shown in the following table.
File Descriptor Types | Corresponding MIME Types |
---|---|
| application/pdf |
html | text/html |
xls | application/xls |
rtf | application/rtf |
csv | text/csv |
ods | application/vnd.oasis.opendocument.spreadsheet |
odt | application/vnd.oasis.opendocument.text |
txt | text/plain |
docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
font | font/* |
img | image/* |
jrxml | application/jrxml |
jar | application/zip |
prop | application/properties |
jrtx | application/jrtx |
xml | application/xml |
css | text/css |
accessGrantSchema | application/accessGrantSchema |
olapMondrianSchema | application/olapMondrianSchema |
You can cusomize this list of MIME types in the server by editing the contentTypeMapping map in the file .../WEB-INF/applicationContext-rest-services.xml. You can change MIME types for predefined types, add MIME types, or add custom types.
Recommended Comments
There are no comments to display.