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

Provide getDataUrl method for previews #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions meteor-file-uploader.js

This file was deleted.

28 changes: 28 additions & 0 deletions meteor-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,35 @@ EJSON.addType("MeteorFile", MeteorFile.fromJSONValue);

/************************ Client *********************************************/
if (Meteor.isClient) {

/**
* Create a binary string out of an array of numbers (bytes), each varying
* from 0-255.
*
* @param {Array} bytes The array of numbers to transform into a binary str.
* @return {string} The byte array as a string.
*/
function arrayToBinaryString(bytes) {
if (typeof bytes != typeof []) {
return null;
}
var i = bytes.length;
var bstr = new Array(i);
while (i--) {
bstr[i] = String.fromCharCode(bytes[i]);
}
return bstr.join('');
}

function toDataURL(contentType, uint8Array) {
return 'data:' + contentType + ';base64,' +
self.btoa(arrayToBinaryString(uint8Array));
}

_.extend(MeteorFile.prototype, {
getDataUrl: function() {
return toDataURL(this.type, this.data);
},
read: function (file, options, callback) {
if (arguments.length == 2)
callback = options;
Expand Down
2 changes: 0 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ Package.describe({

Package.on_use(function (api) {
api.use(["underscore", "ejson"], ["client", "server"]);
api.use(["handlebars", "spark"], "client");
api.add_files(["meteor-file.js"], ["client", "server"]);
api.add_files("meteor-file-uploader.js", "client");

if (typeof api.export !== 'undefined') {
api.export("MeteorFile", ["client", "server"]);
Expand Down