0

I have looked all over and none of the issues I am finding fixes my issue.

I have a program that sends json strings to a server. I upload and download files. They are between a vb client and php server. I can go from the server to the client just fine but when I try to send a file to the server the base64 is invalid.

Here is my code on the vb side.

Dim bytes As Byte()
bytes = System.IO.File.ReadAllBytes(filename)

Dim base64String As String = Convert.ToBase64String(bytes)  

If I send a text file and decode it manually 80% of the file is there then it just goes to garbage. Is there some other setting for convert.tobase64String that I'm missing?

Here is the base64 inside the json

VGhpcyBrbm93bGVkZ2UgYmFzZSBhcnRpY2xlIHNob3VsZCBoYXZlIHRoZSBtYWludGVuYW5jZSBwbGFuIHRoYXQgRGF2aWQgaXMgcmVmZXJlbmNpbmcuDQoNCmh0dHBzOi8vc3VwcG9ydGNlbnRlci5lbWRzLmNvbS9hcnRpY2xlcy9Ucm91Ymxlc2hvb3RpbmcvSG93LWRvLUktcmVpbmRleC1teS1Tb2x1dGlvbi1TZXJpZXMtODAtZGF0YWJhc2Umcz1yZWluZGV4JTIwJnA9MSANCg0KSWYgeW91IGhhdmUgYW55IHF1ZXN0aW9ucyBhYm91dCBpdCBwbGVhc2UgZmVlbCBmcmVlIHRvIGdpdmUgdXMgYSBjYWxsIGF0IHRoZSBJVCBkZXBhcnRtZW50ICgxLTgwMC01NjUtNTU2NCBvcHRpb24gMikNCg0KLUFydA0KDQogICAgRGVjZW1iZXIgNSwgMjAxNyDCtyBMaWtlMCDCtyBEaXNsaWtlMCDCtyBGbGFnDQoNCkNhc2V5IFdpbGxpYW1zQ2FzZXkgV2lsbGlhbXMNCkhleSBKaW0sDQoNCkkga25vdyB0aGlzIGlzIHN1cGVyIG9sZCwgYnV0IGlmIHlvdSdyZSBzdGlsbCBsb29raW5nIGZvciBhbiBhbnN3ZXIgLSB5b3Ugc2hvdWxkIE5FVkVSIFNocmluayB0aGUgRGF0YWJhc2UgdW5sZXNzIGFic29sdXRlbHkgbmVlZGVkLiANCg0KSGVyZSBpcyBhIGNvcnJlY3QgbGlzdCBvZiBNYWludGVuYW5jZSBQbGFucyBhbmQgaG93IG9mdGVuIHRoZSBzaG91bGQgcnVuOg0KQmFja3VwIExvZyBGaWxlcyBvZiBhbGwgREI6IEV2ZXJ5IDMwIE1pbnV0ZXMNClByaW1hcnkgTWFpbnRlbmFuY2UgUGxhbjogQ2hlY2sgRGF0YWJhc2UgSW50ZWdyaXR5PlJlYnVpbGQgSW5kZXg QmFjayBVcCAoRnVsbCkgLSBFdmVyeSBkYXkgaWYgcG9zc2libGUsIGFmdGVyIGhvdXJzLg0KIA==

Here is the textfile that made it.

This knowledge base article should have the maintenance plan that David is referencing.

https://supportcenter.emds.com/articles/Troubleshooting/How-do-I-reindex-my-Solution-Series-80-database&s=reindex%20&p=1 

If you have any questions about it please feel free to give us a call at the IT department (1-800-565-5564 option 2)

-Art

    December 5, 2017 · Like0 · Dislike0 · Flag

Casey WilliamsCasey Williams
Hey Jim,

I know this is super old, but if you're still looking for an answer - you should NEVER Shrink the Database unless absolutely needed. 

Here is a correct list of Maintenance Plans and how often the should run:
Backup Log Files of all DB: Every 30 Minutes
Primary Maintenance Plan: Check Database Integrity>Rebuild Index>Back Up (Full) - Every day if possible, after hours.

Here is what comes out on the server side

This knowledge base article should have the maintenance plan that David is referencing.

https://supportcenter.emds.com/articles/Troubleshooting/How-do-I-reindex-my-Solution-Series-80-database&s=reindex%20&p=1

If you have any questions about it please feel free to give us a call at the IT department (1-800-565-5564 option 2)

-Art

    December 5, 2017 · Like0 · Dislike0 · Flag

Casey WilliamsCasey Williams Hey Jim,

I know this is super old, but if you're still looking for an answer - you should NEVER Shrink the Database unless absolutely needed.

Here is a correct list of Maintenance Plans and how often the should run: Backup Log Files of all DB: Every 30 Minutes Primary Maintenance Plan: Check Database Integrity>Rebuild Indexbase64: invalid input
djv
  • 15,168
  • 7
  • 48
  • 72
  • You have included PHP tag, and I see why you did it, but in fact this question has rather nothing to do with PHP, which is a little bit misleading. – Dharman Jan 24 '19 at 20:13
  • I am sending this to php and the decode on it just sends out a blank. base64 on the server at least gives some info. – darkstar2002 Jan 24 '19 at 20:20
  • This is not the output I get from a base64 conversion of your sample text. The base64 string you have posted is not correct (wrong termination), it also includes a line break near the end. Check out the serialization procedure. – Jimi Jan 24 '19 at 20:44
  • That Base64 string is broken. There is a space character near the end. If I remove it, then it's an invalid length. If replace it with a legal character, I get the expected output. – glenebob Jan 24 '19 at 20:44
  • The correct Base64 string has a '/' character where the white space is in the question, and that's the only '/' present. It's likely being stripped during construction of the HTTP request. The string needs to be encoded or escaped in some fashion to avoid that. – glenebob Jan 24 '19 at 21:27
  • Yes I know the base64 is broken. That is why I am asking for help. Microsoft .net is outputing wrong base64. – darkstar2002 Jan 28 '19 at 14:01

1 Answers1

0

You can use Uri.EscapeDataString() to encode your Base64 string as body data. This will encode the slash as %2F and should be automatically decoded by the server.

Dim encodedString As String = Uri.EscapeDataString(base64String)

EDIT:

For data longer than 65520 chars you can use WebUtility.UrlEncode() instead until the Uri class's problem is fixed (if it ever will be), but note that WebUtility too has some quirks of its own.

Dim encodedString As String = WebUtility.UrlEncode(base64String)

Uri.EscapeDataString() is the most RFC-compliant method today and thus is the preferred solution (when possible).

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75