How do you convert binary data to string on the client? I have tried all the EJSON* functions with no luck.
I am trying to save images as binary in mongo. First I remove the part with “data:image/jpeg;base64,” then I save the rest with EJSON.newBinary(data). I figure - either I’m doing something wrong or the client can’t convert binary. It works if I don’t strip out the “data:image…” part but then it gets stored as a string which is unnecessarily bigger.
I’m downsizing, cropping and properly orienting the image on the client. I figure I could save some bandwidth that way (images from smart phones are huge). But now I’m stuck at how to display them again after making them binary.
ImageData is no go for IE it seems. Does it really take all this? Why do meteor have a way to convert a string to binary and then no way of converting it back? This sounds crazy so I guess I’m just missing something here?
Use .toBlob() instead and just save that server-side. Again you don’t need to make it a string.
To show it again you transmit it from the server back to the client and make a url for the blob with URL.createObjectURL(). Then just feed that as the src for either an img tag or a new Image() object.