0

I have an application that makes a call to a third party web API that returns a String that looks something like this:

"JVBERi0xLjMNCiXi48/TDQoxIDAgb2JqDQo8PA0KL1R5cGUgL091dGxpbmVzDQovQ291bnQgMA0KPj4NCmVuZG9iag0KMiAwIG9iag0KDQpbL1BERiAvVGV4dCAvSW1hZ2VDXQ0KZW"

(It's actually much longer than that but I'm hoping just the small snippet is enough to recognize it without me pasting a string a mile long)

The documentation says it returns a Byte array but when I try to accept it as a Byte array directly, I get errors. Part of my problem here is that the documentation isn't completely clear what the Byte array represents. Since it's a GetReport function I'm calling, I'm guessing it's a PDF but I'm not 100% sure as the documentation doesn't say at all.

So, anyway, I'm getting this String and I'm trying to convert it to a PDF. Here's what that looks like:

Dim reportString As String = GetValuationReport(12345, token.SecurityToken)

Dim report As Byte() = System.Text.Encoding.Unicode.GetBytes(reportString)
File.WriteAllBytes("C:\filepath\myreport.pdf", report)

I'm pretty sure that the middle line converts the String into a new Byte array rather than simply converting it into its Byte array equivalent but I don't know how to do that.

Any help would be fantastic. Thanks!

1 Answer 1

3

It looks like your string may be Base64 encoded, in which case you would use this to convert it to bytes:

Dim report As Byte() = Convert.FromBase64String(reportString)
Sign up to request clarification or add additional context in comments.

1 Comment

Ha! You're a genius. That's exactly what my problem was.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.