AlexF11 AlexF11 - 2 months ago 30
Vb.net Question

Convert base64 to pdf

I'm trying to convert a base64 string to a pdf in my web service but for some reason it isn't working, my webserver returns a bad request. The last 4 lines are causing the issue.

I've followed a bunch of examples and gotten this far

Dim base64file As String = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAB/lBMVEX///+VlZWZmZmRlpaTlpaTlZaSlZaTk5ORlZWTlZWTlZaSmJj///+TlpaTlZaTlZaUlJSAgICSlZWTlJaTlZaTlpaOjo6SlZeTlZaTlZaUlJaPj4+TlZWTlZaTlZeTlZeVlZWUlZaWlpaUlZWTlpaTlZaWlpaTlZeTlZaTlZaTlpaZmZmUlZaVlZWTlZaTlZeUlJiSlZaTlZaSlJaWlpaTlZaTlZaPmZmTlZaTlpaVlZWSlZaVlZWSkpKTlZaTlZWTlJaTlZaTlpaSkpKUlZaAgICLi4uTlJaTlZaTlpaAqqqUlJeTlZaTlZeVlZWUlpaTlZaUlZWUlJSfn5+UlpaSlpaTlZaUlZWRl5eQlpaTlZaSl5eUlZWZmZmTlZeTlZaTlZaUlpaUlJeTlZaSlpaTlZWUlZaTlZWTlZeSlZWTlZWTk5OUlpaTlpaTlJaSlJaOnJyJnZ2TlZWUlJiSlZeSkpKSlZWTlpaSlJeTlZaTlJaXl5eTlJaSlJaVlZWTlpaTlZaUlZaSkpiTlJaTk5iTlZeUlZWUlZeTlZWTk5mTlZWTlZaUlJaTlpaTlZaUlJSUlJSTlZaTlZaSlZeTlZaQkJuUlJSTlZaTlZaTlZWVlZWSlZeTlZaTlJaUlJeTlZWUlpaUlJSTlZaTlZeSlZWTlZWTlZWVlZWTlZYAAABfkBHsAAAAqHRSTlMAHQozrP3RGkG64ioBUMjvPgRe1fhVCWzg/nAQe+qQiRjyIpjc7i6m/OZoBdg8tHhFw/aIEfuXGdqnJLcwFc/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y4wK/RcXGE8iMX+QUmLhiSL10mQ774Cq8cpbFR3vcKOaXKy5cYg2qUrl4j73qd3Yp2GmtnF3+drOzaVQmrOQPE8A0yT2726MQ9qfYyMdRNMlFuhMknowG5CemQGBtXxWXDcnC4TGXGx8hjm3xbigwQb90mW9F6J/XZehdiZMAHYnBXvnnvtJLF376lSMUGKE3QrbjnkxWTZBdHJ+Ww7x5d/MR0L6UxIFtxnxzegyQ+BHiEjwEe4yOAh5h8QA70fljTpTVAfEJLt3IEnkZlg+hTiD2jpf1Er2INupzMWT2nl5v3BcoG+ILeIIHnjCTO/ebrfsmEpVevI0lUDTAZef1KYgTJKUMxFjIviNHUjwrFAM1RJugeE7QCjHjeIA/VgMHbdy4Qo2LSltlAmmiA9HjflMlgIAAzwvTh40wGnz5DRuR+iaYz6P9amjmf4Nt3sYE/+z8dRY1Ggx81WacTBH/aWYPQr+Bs8gn6huKaQbyjZZbpFFNJ1aB2ag7pFGOJ3wC/E3/mmE7gIrfLoGvu+f8I/gKO8wApeMN4xQAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNi0wMy0yOVQxODo0NzoyNCswMjowMCvzrPoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTYtMDMtMjlUMTg6NDc6MjQrMDI6MDBarhRGAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAABJRU5ErkJggg=="
Dim bytes As Byte() = Convert.FromBase64String(base64file)

Dim stream As New FileStream("c:\Users\me\Desktop\itworks.pdf", FileMode.CreateNew)
stream.Write(bytes, 0, bytes.Length)
stream.Close()
opResult.success = True


What am I doing wrong?

Answer

As the other guys mentioned you should add logs to your code to figure out the error.

This has some decent suggestions: Where does Console.WriteLine go in ASP.NET?

Otherwise you might be able to add a try-catch around the eroneous code and then print the exception to your log.

I'd assume that the log would show up in your browser much like a console.log would in JS.

If you run chrome simply get the developer tools up and find your console when yo uahve set up the code. That way you might get some more information surrounding the error.

This msdn URL has some information about try-catches: https://msdn.microsoft.com/en-us/library/f9shkfdd.aspx

But basically the idea is that you should be using something similar to:

Try
'Paste the code you are trying
Catch ex As Exception
'Add the log of your choice. In JS it would be Console.log(ex.message)
End Try
Comments