Forum Discussion

Prajakta_Kale's avatar
Prajakta_Kale
Occasional Visitor
4 years ago

An error occurred [Your InputStream was neither an OLE2 stream, nor an OOXML stream]

I downloaded an attachment from an URL using groovy script . An attachment is in .xlsx format.
But while reading that .xlsx file it is throwing below error:

 

Your InputStream was neither an OLE2 stream, nor an OOXML stream] 

 

So I tried to read raw response as per suggestions using below snippet:

 

    def DownloadLink="https://bestbuyuat.service-now.com/api/now/attachment/4519d6eb1b592c90a531c8866e4bcb4d/file"
    def snowuserauth="Basic"
    def userCredentials2="${username}:${passwd}"
​    def httpConn =  new URL(DownloadLink).openConnection() as HttpURLConnection
    basicAuth1 = "${snowuserauth} " + new String(new sun.misc.BASE64Encoder().encode(userCredentials2.getBytes()));
    println("*** encoded1 "+basicAuth1);
    httpConn.setRequestProperty ("Authorization", basicAuth1);
    int BUFFER_SIZE = 4096;
    int responseCode1 = httpConn.getResponseCode();
    *def rawResponse = context.httpResponse.getRawResponseBody();
    InputStream inputStream = new ByteArrayInputStream(rawResponse);

 

But then it is giving me below error:

 

{returnCode=1, errorStream={returnCode=-1000, errorStream=Exeception while executing script: [{}]java.lang.NullPointerException: Cannot get property 'httpResponse' on null object}}

 

Please suggest on this.