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 File. 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. The request parameters contain information that becomes the name and description of the new file resource.
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: "label" containing the name of the file resource "description" containing a description for the resource "type" containing a file type shown in “File Types and MIME Types” "data" containing the file contents | ||
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: <file-description> - Becomes the description field of the created file resource Content-Disposition: attachment; filename=<filename> - Becomes the name of the file resource | |||
Content-Type | Content | ||
{MIME type} | The MIME type from “File Types and MIME Types” that corresponds to the desired file type. The body of the request 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 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. |
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.