Retrieving binary file content using Javascript, base64 encode it and reverse-decode it using Python

So I’m answering to myself — and sorry for that — but I think it might be useful for someone as lost as I was 😉 So you have to use ArrayBuffer and set the responseType property of your XMLHttpRequest object instance to arraybuffer for retrieving a native array of Bytes, which can be converted to base64 … Read more

Base64 Encode a PDF in C#?

Use File.ReadAllBytes to load the PDF file, and then encode the byte array as normal using Convert.ToBase64String(bytes). Byte[] fileBytes = File.ReadAllBytes(@”TestData\example.pdf”); var content = Convert.ToBase64String(fileBytes);

Convert byte[] to base64 and ASCII in Python

The simplest approach would be: Array to json to base64: import json import base64 data = [0, 1, 0, 0, 83, 116, -10] dataStr = json.dumps(data) base64EncodedStr = base64.b64encode(dataStr.encode(‘utf-8’)) print(base64EncodedStr) print(‘decoded’, base64.b64decode(base64EncodedStr)) Prints out: >>> WzAsIDEsIDAsIDAsIDgzLCAxMTYsIC0xMF0= >>> (‘decoded’, ‘[0, 1, 0, 0, 83, 116, -10]’) # json.loads here ! … another option could be using … Read more

Base64 Encoding safe for filenames?

Modified Base64 (when /,= and + are replaced) is safe to create names but does not guarantee reverse transformation due to case insensitivity of many file systems and urls. Base64 is case sensitive, so it will not guarantee 1-to-1 mapping in cases of case insensitive file systems (all Windows files systems, ignoring POSIX subsystem cases). … Read more

Using raw image data from ajax request for data URI

Thanks for that. I’ve done a bit more digging on this and it turns out there is a solution at least on current versions of Firefox and Chrome (EDIT: IE10 works too). You can use XMLHttpRequest2 and use a typed array (Uint8Array). The following code works: <!DOCTYPE html> <html> <head> <script type=”text/javascript”> function init() { … Read more

play .wav sound file encoded in base64 with javascript

That doesn’t look like the correct way to use the Audio constructor for HTMLAudioElement / <audio>. Slight adjustment var snd = new Audio(“data:audio/wav;base64,” + base64string); snd.play(); If it works in console but not in script, it may be getting garbage collected, in which case scope it so it will stay var Sound = (function () … Read more

GETting a URL with an url-encoded slash

This is a terrible hack, bound to be incompatible with future versions of the framework and so on. But it works! (on my machine…) Uri uri = new Uri(“http://example.com/%2F”); ForceCanonicalPathAndQuery(uri); using (WebClient webClient = new WebClient()) { webClient.DownloadData(uri); } void ForceCanonicalPathAndQuery(Uri uri){ string paq = uri.PathAndQuery; // need to access PathAndQuery FieldInfo flagsFieldInfo = typeof(Uri).GetField(“m_Flags”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)