Closed antonymott closed 1 year ago
b64encode returns a binary, not a string. you need to add a decode()
if you want it to be transported as a string
>>> import os, base64
>>> base64.b64encode(os.urandom(16))
b'3w0O75uLD2lkGye2QWlS2w=='
>>> base64.b64encode(os.urandom(16)).decode()
'IbNb3LSimKfUPPULMKZL+A=='
>>>
Problem solved...thanks Tobias!
crossbar v21.3.1 linux
I realize wamp is generally for small messages, and the image I'm sending is tiny. But base64 from python is changed in transit, not a valid URL. In js, I also tried btoa() and atob() more out of desperation as it seems neither should be necessary as base64 is such a common network protocol.
pseudocode in python: @register('com.test.b64image) @inlineCallbacks def returnBase64(self): with open(uri, 'rb') as imageFile: encodedString = base64.b64encode(imageFile.read()) print(encodedString)
in js: const res = await session'call' console.log(res) ...FCQUFELzRRRGVSWGhwWmdBQVNVa3FBQWdBQUFBR0FCSUJBd0FCQUFBQUFRQUFBQm9CQlF
The JavaScript string is completely changed.