Requesting the Contents of a File Resource

In order to retrieve the contents of a file, first retrieve the descriptor of its enclosing resource to find the resource URI. The resource can either be internal to the report, or referenced from the repository. In either case it has a URI in the repository that we can extract from the parent resource.

In the previous sample, we see the attachments that are internal to the AllAccounts report. There is an image named AllAccounts_Res3 that is not a reference and has data. To download the image, we create the following request to the resource service, giving it the internal URI of the image and fileData=true.

Notice that the URI to the file includes the path AllAccounts_files. This is a local path that exists to access the local resources of the report, not a folder that exists in the repository.

In the case of a resource that is referenced in the repository, you can download the contents of the file in the same way. From the resource descriptor in the previous section, we see there is another resource where PROP_IS_REFERENCE is true. We can extract the repository URI from the PROP_REFERENCE_URI property and use that with fileData=true to obtain the image:

The descriptor does not store the extension nor the format of a file resource. Jaspersoft recommends using the filename with the file extension as the resource ID when creating file resources so that the extension is available when downloading the file.