Downloading a visit or location attachment - AquaticInformatics/aquarius-sdk-net GitHub Wiki
The Publish API will report URLs to location or visit attachments.
- The
GET /GetLocationData
response includes anAttachments
collection, for all location attachments. - The
GET /GetFieldVisitsData
andGET /GetFieldVisitDataByLocation
responses include anAttachments
collection, for all visit attachments.
Each Attachment
object has some relevant properties:
Property | Description |
---|---|
Url |
A URL, relative to the Publish API endpoint, which can be downloaded via a regular HTTP GET request. |
Filename |
The uploaded filename, which may contain a directory path. Use this filename as the suggested filename when you download the file. |
AttachmentType |
The type of attachment, automatically determined by AQTS. One of Image , Video , Audio , Pdf , Xml , Text , Binary , Zip , LoggerFile , GeneratedReport , Csv , FieldDataPlugin , AquaCalc , Swami , FlowTracker , HFC , ScotLogger , SonTek , or WinRiver . |
AttachmentCategory |
The user-selected attachment category. One of None , LocationPhoto , Notes , Site , Channel , Measurement , CrossSection , Inspection , InventoryControl , LevelSurvey , or Report . |
GpsLatitude GpsLongitude
|
For Image or Video files, the latitude/longitude values extracted from the image metadata. This can be useful to overlay attachment images on a map. |
The attachment byte content can be retrieved from the URL
property as a regular HTTP GET request. The IServiceClient
interface from the SDK has some convenient methods to make this easy.
public void DownloadAttachment(string destinationFolder, Attachment attachment)
{
using (var httpResponse = Client.Publish.Get<HttpWebResponse>(attachment.Url))
{
// Removes any original path stored in AQTS when the file was uploaded
var path = Path.Combine(destinationFolder, Path.GetFileName(attachment.FileName));
var actualBytes = httpResponse.GetResponseStream().ReadFully();
File.WriteAllBytes(path, actualBytes);
}
}