1

I'm using classic asp & JSON to convert html to pdf. I send the request using the following:

        ''Convert output to pdf
        varURL = "https://" & varServerLive & "/import/" & fileName

        postURL = "https://v2.convertapi.com/convert/htm/to/pdf?Secret=SECRET_KET&File=" & varURL & "&StoreFile=true"
        parmToSend = "{""Parameters"":[{""Name"":""File"",""FileValue"":{""url"": """ & varURL & """}}," & _
            "{""Name"":""WebHook"",""Value"":""" & varURL & """}" & _
            "]}"

        Set ServerXmlHttp = Server.CreateObject("MSXML2.XMLHTTP.6.0")
        ServerXmlHttp.open "POST", postURL
        ServerXmlHttp.setRequestHeader "Accept", "application/json"
        ServerXmlHttp.setRequestHeader "Content-Type", "application/json"
        ServerXmlHttp.send parmToSend

        ''Get response
        responseText = ServerXmlHttp.responseText
        response.write(responseText)

        set myJson = JSON.parse(responseText)
        varFileUrl = myJson.Files.Url
        response.write(varFileUrl)

I get the following response:

responseText:

{"ConversionCost":2,"Files":[{"FileName":"54-25062020177.pdf","FileExt":"pdf","FileSize":48596,"FileId":"542c6f079fe5722bdbac2f73f84652d3","Url":"https://v2.convertapi.com/d/542c6f079fe5722bdbac2f73f84652d3/54-25062020177.pdf"}]}

Which is all good, but when I try to return the fileURL I get an error:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'url'

/docs/members/cert.asp, line 122

Do you see any reason why the url is not being returned? Am I calling the url correctly (eg. myJson.Files.Url)?

Any help would be much appreciated.

Tomas
  • 17,551
  • 43
  • 152
  • 257
Benzine
  • 472
  • 1
  • 5
  • 19
  • 1
    It's because `Files` is an array so you need to specify which object in the array you are getting the `Url` property of. What JSON parser are you using? – user692942 Jun 25 '20 at 00:40
  • Interesting, you seem to be returning different response data than [your last question](https://stackoverflow.com/q/62555555/692942). Personally, prefer the request where the Base64 data is returned in the response because this method will require another HTTP call to get the file from the Url, which seems a pointless step. – user692942 Jun 25 '20 at 00:51
  • Yes, I've changed the request to return thr url of the created pdf rather than the fileData. – Benzine Jun 25 '20 at 04:03
  • Im using this json file as an include, I use this one throughout my asp application without issues. https://www.gbca.org.au/global/json2.min.asp – Benzine Jun 25 '20 at 04:06
  • I'm using myJson.Files.Url to get the url? This should return it yes? – Benzine Jun 25 '20 at 04:21

2 Answers2

1

Sorted. I needed to specify the position in the array, which is strange cause I never needed to do this in other functions.

varFileUrl = myJson.Files.[0].Url

Benzine
  • 472
  • 1
  • 5
  • 19
1

I suggest using content-type:application/octet-stream and you will get file stream instead of JSON, after that you can easily dump that stream into a file. The advantage of using steam response is:

  • Response size will be smaller about 30% than JSON because JSON file data needs to be encoded in Base64,

  • You can read data in chunks.

If you still prefer using JSON then remove StoreFile=true from your request and you will get a File Data instead of URl, decode it using base64 and write to file. You will save one request to the server.

Tomas
  • 17,551
  • 43
  • 152
  • 257