-
Notifications
You must be signed in to change notification settings - Fork 7
Uploading an external report
AQTS 2017.3 added support for uploading externally-generated reports to your AQTS app server. This will allow your users to view reports within AQUARIUS, and will allow AQUARIUS WebPortal to synchronize these reports for public distribution.
File upload operations are standard MIME multipart/form-data
requests. One POST request will contain multiple content parts, separated by boundary markers.
- One part will be the name of the uploaded file plus the file's content, byte for byte.
- Other parts will be any other request parameters required by the operation.
The bare minimum information required to attach an external report is:
- The unique ID of the location to which the report is attached. The uploaded report will belong to the specified AQUARIUS location. You can discover the unique ID of the location using the Publish API, or via the Location Manager details panel.
- A title for the report. This title will be displayed to AQUARIUS (and WebPortal) users.
- The actual report file content. You can attach PDF, JPG, PNG, CSV, or HTML report files.
The multipart MIME spec is rather complex, but the SDK handles all these complexities for you, by providing a set of PostFileWithRequest<TResponse>()
methods. The simplest form takes a Java File object as the file to upload.
import com.aquaticinformatics.aquarius.sdk.timeseries.AquariusClient;
import com.aquaticinformatics.aquarius.sdk.timeseries.servicemodels.Acquisition.*;
import com.aquaticinformatics.aquarius.sdk.timeseries.servicemodels.Publish.*;
import java.io.File;
private AquariusClient _client;
public String uploadExternalReport(String locationIdentifier, String pathToFile, String reportTitle) {
String locationUniqueId = getLocationUniqueId(locationIdentifier);
return _client.Acquisition
.postFileWithRequest(new File(pathToFile), new PostReportAttachment()
.setLocationUniqueId(locationUniqueId)).ReportUniqueId;
}
private String getLocationUniqueId(String locationIdentifier) {
return _client.Publish
.get(new LocationDataServiceRequest().setLocationIdentifier(locationIdentifier))
.UniqueId;
}
If the file content to upload doesn't exist on disk, there are overloaded methods that allow you to supply a filename and a stream separately. This would allow your integration to compose a file in-memory using a InputStream
and upload it to AQTS.
AQTS 2017.3 also added support for HTTP Basic Authentication. This can help integration by allowing standard utilities like curl
to upload external reports in a single command line.
Here is a curl
command line to upload a PDF with a title of "Monthly Rain Forecast" to a location.
$ curl -f -u username:password -F "upload=@folder/MonthlyRainForecast.pdf" -F "Title=Monthly Rain Forecast" "http://yourserver/AQUARIUS/Acquisition/v2/locations/b27e626564e241098897cbd4ea47aab5/attachments/reports"
-
-f
tells curl to fail if it does not receive a2xx
HTTP status response. -
-u username:password
sets the AQUARIUS credentials using HTTP Basic Authentication. -
b27e626564e241098897cbd4ea47aab5
is the unique ID of the target location. -
-F "upload=@folder/MonthlyRainForecast.pdf"
is the path to the file to upload. (Note that the path starts with@
) -
-F "Title=Monthly Rain Forecast"
sets the Title property of the request
Still have questions? Feel free to raise an issue or contact our Support Team
- SDK design philosophy (on the .NET SDK wiki)
- AQTS client concepts
- AQTS code examples
- Troubleshooting tips