Skip to content

Instantly share code, notes, and snippets.

@sergical
Created January 29, 2015 23:12
Show Gist options
  • Save sergical/02969aea2e64dbf8c326 to your computer and use it in GitHub Desktop.
Save sergical/02969aea2e64dbf8c326 to your computer and use it in GitHub Desktop.
filepicker.pickAndStore(
{
multiple: false,
maxFiles: 1,
services: ['COMPUTER', 'GOOGLE_DRIVE', 'DROPBOX']
},{
access:"private"
},
function(InkBlobs){
var fileTotal = 0;
_.each(InkBlobs, function (el) {
fileTotal += el.size;
Session.set('fileTotal', fileTotal);
el.size = bytesToSize(el.size);
var fullName = el.filename;
el.mimetype = fullName;
el.filename = longFileName(el.filename);
});
Session.set('files', InkBlobs);
},
function(FPError){
if(FPError && FPError.code !== 101)
showError(FPError.toString());
}
);
@dylansimpson
Copy link

Once filepicker returns the array of Blobs, pass them to JSZIP to combine then pass the combined zip back to filepicker.pickAndStore()

Here are the filepicker docs:
https://developers.filepicker.io/docs/web/javascript_api/#pickMultiple

JSZip has a good example of how to bundle them up:
https://stuk.github.io/jszip/documentation/examples/downloader.html

@sergical
Copy link
Author

sergical commented Feb 3, 2015

@dylansimpson thanks for that. Sorry it took so long, had to focus on implementing other stuff.
So from my understanding, I have to modify this

      function(InkBlobs){
        var fileTotal = 0;
        _.each(InkBlobs, function (el) {
          fileTotal += el.size;
          Session.set('fileTotal', fileTotal);
          el.size = bytesToSize(el.size);
          var fullName = el.filename;
          el.mimetype = fullName;
          el.filename = longFileName(el.filename);
        });
      Session.set('files', InkBlobs);
    },

to

      function(InkBlobs){
        var fileTotal = 0;
        _.each(InkBlobs, function (el) {
          fileTotal += el.size;
          Session.set('fileTotal', fileTotal);
          el.size = bytesToSize(el.size);
          var fullName = el.filename;
          el.mimetype = fullName;
          el.filename = longFileName(el.filename);
        });
      // zipping it up
      var zip = new JSZip();
      zip.file(InkBlobs);
      Session.set('files', zip);
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment