Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EJSON._base64Decode with PDFs and Images #1001

Closed
cmather opened this issue Apr 29, 2013 · 8 comments
Closed

EJSON._base64Decode with PDFs and Images #1001

cmather opened this issue Apr 29, 2013 · 8 comments

Comments

@cmather
Copy link
Contributor

@cmather cmather commented Apr 29, 2013

@sixolet

Issue
EJSON seems to be incorrectly decoding certain base64 encoded strings. Specifically, I have been unable to correctly decode any encoded pdf, png or jpeg files. I ran out of time figuring out the exact causality but all regular text files seem to be decoded correctly. Encoding seems to be working correctly. I baselined against Node's Buffer encoding/decoding methods to determine correctness. You can see those few lines in the repro project below.

Use Case
Uploading a file from the browser using HTML5 and DDP.

Repro
https://github.com/cmather/ejson-base64-repro

@raix
Copy link
Contributor

@raix raix commented May 1, 2013

Replicated and same issue with EJSON.base64Decode - added console.log('Original: ', arrayView.buffer); just to be 110%

@cmather: I tried something like this when making collectionFS - you dont have to base64 encode to send data to the server via methods. I'm assuming thats what you are up to, since you are decoding?

@cmather
Copy link
Contributor Author

@cmather cmather commented May 1, 2013

Thanks for confirming the issue @raix. I'm serializing a Uint8Array as a property on a custom EJSON type. I guess I can send the plain binary string vs. a serialized Uint8Array. Is that what you're suggesting? Alternatively, I could just pass the ArrayBuffer as an object over the wire, and it would also probably work fine.

@raix
Copy link
Contributor

@raix raix commented May 1, 2013

@cmather well, I just use the filereader readAsBinaryString I slice the file into chunks of 256_1024 bytes (gridFS default size) - I think the onloadend -> evt.target.result is Uint8Array https://github.com/raix/Meteor-CollectionFS/blob/master/collectionFS_client.api.js#L302
But on the server its simply thrown into the db in the server method: https://github.com/raix/Meteor-CollectionFS/blob/master/collectionFS_server.js#L38
But it could just as easy go directly into a node.js Buffer https://github.com/raix/Meteor-CollectionFS/blob/master/collectionFS_server.api.js#L107
using blob.write *(credit goes to @nhibner for simplifying)_
My old hacks on that: CollectionFS/Meteor-CollectionFS@6b327ef#L4R105
the collectionFS client-side code is next for a clean up... Was my first code ever in Meteor

@cmather
Copy link
Contributor Author

@cmather cmather commented May 1, 2013

@raix Cool :-). I'll be interested in your feedback on the eventedmind file upload episode being published on Friday.

@raix
Copy link
Contributor

@raix raix commented May 1, 2013

👍 @cmather, looking forward to it, big fan :)

@crapthings
Copy link

@crapthings crapthings commented May 1, 2013

+1 upload tut chris, and can u tell me how do u make your video tag work with page redirect on eventedmind?
im sorry to put issue to this post, but help pls.

https://github.com/crapthings/meteor-video-tag

@raix
Copy link
Contributor

@raix raix commented May 1, 2013

I got it.. PR comming up

@glasser
Copy link
Member

@glasser glasser commented May 6, 2013

Thanks @raix. Adapted this to 3952be8 and added a test, now on devel.

@glasser glasser closed this May 6, 2013
emgee3 added a commit to oortcloud/ddp-ejson that referenced this issue May 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants