andrewmrichards
Registered User.
- Local time
- Today, 15:39
- Joined
- Mar 15, 2012
- Messages
- 18
Morning all!
I'm working on a database which is designed to connect to an app called Canvas (www dot gocanvas dot com). It's for a client which runs a team of heating engineers. All the information regarding the engineer's job is uploaded to Canvas through their API as an XML file, and the engineers use an app on tablet to view the job details. When the engineer goes to their customer and does some work, the completed info (which parts were serviced etc) is then downloaded as an XML file via the API into the database. Also, the customer signs on the engineer's tablet to confirm that the work has been done.
Although the XML files for the job data upload and download fine, there's a different API for getting a download of the JPEG which contains the customer signature, and I'm having real problems finding out how to use this.
The API guide says this:
----
The Submissions API is restricted to authenticated users and requires a username and apassword to access. In addition, the ID field is required. If these fields aren't specified, an error is returned.
The result of this webservice invocation will be either a standard JPEG image or an error code.
Example:
htt ps : / / www . gocanvas . com / apiv2 / images . xml? image_id=1 & username= test @ gocanvas .com &password=test
----
All my code (which I've pasted at the foot of this message seems to work fine. There are no errors, and the ResponseBody object appears to contain a byte stream which would be the jpeg... if only I could get it into a jpeg file!
Does anyone have any clue how I go about taking this "stuff" that's come back in the responsebody and actually create a jpeg image file from it? I feel that I'm so close that I can smell it, but can't get the last step!
Many thanks for any help.
Andrew
Here's the existing code (spaces inserted into URL to allow me to post!):
I'm working on a database which is designed to connect to an app called Canvas (www dot gocanvas dot com). It's for a client which runs a team of heating engineers. All the information regarding the engineer's job is uploaded to Canvas through their API as an XML file, and the engineers use an app on tablet to view the job details. When the engineer goes to their customer and does some work, the completed info (which parts were serviced etc) is then downloaded as an XML file via the API into the database. Also, the customer signs on the engineer's tablet to confirm that the work has been done.
Although the XML files for the job data upload and download fine, there's a different API for getting a download of the JPEG which contains the customer signature, and I'm having real problems finding out how to use this.
The API guide says this:
----
The Submissions API is restricted to authenticated users and requires a username and apassword to access. In addition, the ID field is required. If these fields aren't specified, an error is returned.
The result of this webservice invocation will be either a standard JPEG image or an error code.
Example:
htt ps : / / www . gocanvas . com / apiv2 / images . xml? image_id=1 & username= test @ gocanvas .com &password=test
----
All my code (which I've pasted at the foot of this message seems to work fine. There are no errors, and the ResponseBody object appears to contain a byte stream which would be the jpeg... if only I could get it into a jpeg file!
Does anyone have any clue how I go about taking this "stuff" that's come back in the responsebody and actually create a jpeg image file from it? I feel that I'm so close that I can smell it, but can't get the last step!
Many thanks for any help.
Andrew
Here's the existing code (spaces inserted into URL to allow me to post!):
Code:
Sub DownloadImageFile()
Dim xhr As Object
Dim webServiceURL As String
Dim actionType As String
Dim PostData As String
Dim strResult As String
Dim blnSuccess As Boolean
Dim strDownloadedFilePath As String
Set xhr = CreateObject("Microsoft.XMLHTTP")
webServiceURL = "htt ps : // ww w. gocanvas .com/ apiv2 /images.xml? username={our-username}& password={our-password}&image_id={1234}"
xhr.Open "POST", webServiceURL, False
xhr.setRequestHeader "Content-Type", "image/jpeg"
xhr.setRequestHeader "Content-Length", Len(PostData)
xhr.Send PostData
blnSuccess = (xhr.Status = 200)
If blnSuccess Then
strResult = xhr.responsebody 'xhr.responsebody does now appear to contain a byte stream
Else
MsgBox "The signature could not be downloaded." & vbNewLine & vbNewLine & _
"The message receieved from the server was: " & vbNewLine & xhr.Status & ": " & xhr.statusText
strResult = xhr.responseText
End If
If blnSuccess Then
'Save my image file here!
End If
Set xhr = Nothing
End Sub