Code Monkey home page Code Monkey logo

meteor-files's Introduction

support support Mentioned in Awesome ostrio:files GitHub stars

Files for Meteor.js

Stable, fast, robust, and well-maintained Meteor.js package for files management using MongoDB Collection API. What does exactly this means? Calling .insert() method would initiate a file upload and then insert new record into collection. Calling .remove() method would erase stored file and record from MongoDB Collection. And so on, no need to learn new APIs. It's flavored with extra low-level methods like .unlink() and .write() for complex integrations.

ToC:

Key features

Installation:

Install ostrio:files from Atmosphere

meteor add ostrio:files

ES6 Import:

Import in isomorphic location (e.g. on server and client)

import { FilesCollection } from 'meteor/ostrio:files';

API overview

For detailed docs, examples, and API β€” read documentation section.

  • FilesCollection Constructor [Isomorphic] - Initialize FilesCollection
  • insert() [Client] - Upload file(s) from client to server
  • find() [Isomorphic] - Create cursor for FilesCollection
  • remove() [Isomorphic] - Remove files from FilesCollection and "unlink" (e.g. remove) from FS
  • findOne() [Isomorphic] - Find one file in FilesCollection
  • write() [Server] - Write Buffer to FS and FilesCollection
  • load() [Server] - Write file to FS and FilesCollection from remote URL
  • addFile() [Server] - Add local file to FilesCollection from FS
  • unlink() [Server] - "Unlink" (e.g. remove) file from FS
  • link() [Isomorphic] - Generate downloadable link

new FilesCollection([config]) [Isomorphic]

Read full docs for FilesCollection Constructor

Shared code:

import { Meteor } from 'meteor/meteor';
import { FilesCollection } from 'meteor/ostrio:files';

const imagesCollection = new FilesCollection({
  collectionName: 'images',
  allowClientCode: false, // Disallow remove files from Client
  onBeforeUpload(file) {
    // Allow upload files under 10MB, and only in png/jpg/jpeg formats
    if (file.size <= 10485760 && /png|jpg|jpeg/i.test(file.extension)) {
      return true;
    }
    return 'Please upload image, with size equal or less than 10MB';
  }
});

if (Meteor.isClient) {
  Meteor.subscribe('files.images.all');
}

if (Meteor.isServer) {
  Meteor.publish('files.images.all', function () {
    return imagesCollection.find().cursor;
  });
}

insert(settings[, autoStart]) [Client]

Read full docs for insert() method

Upload form (template):

<template name="uploadForm">
  {{#with currentUpload}}
    Uploading <b>{{file.name}}</b>:
    <span id="progress">{{progress.get}}%</span>
  {{else}}
    <input id="fileInput" type="file" />
  {{/with}}
</template>

Shared code:

import { FilesCollection } from 'meteor/ostrio:files';
const imagesCollection = new FilesCollection({collectionName: 'images'});
export default imagesCollection; // import in other files

Client's code:

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
Template.uploadForm.onCreated(function () {
  this.currentUpload = new ReactiveVar(false);
});

Template.uploadForm.helpers({
  currentUpload() {
    return Template.instance().currentUpload.get();
  }
});

Template.uploadForm.events({
  'change #fileInput'(e, template) {
    if (e.currentTarget.files && e.currentTarget.files[0]) {
      // We upload only one file, in case
      // multiple files were selected
      const upload = imagesCollection.insert({
        file: e.currentTarget.files[0],
        chunkSize: 'dynamic'
      }, false);

      upload.on('start', function () {
        template.currentUpload.set(this);
      });

      upload.on('end', function (error, fileObj) {
        if (error) {
          alert(`Error during upload: ${error}`);
        } else {
          alert(`File "${fileObj.name}" successfully uploaded`);
        }
        template.currentUpload.set(false);
      });

      upload.start();
    }
  }
});

For multiple file upload see this demo code.

Upload base64 string (introduced in v1.7.1):

// As dataURI
imagesCollection.insert({
  file: 'data:image/png,base64str…',
  isBase64: true, // <β€” Mandatory
  fileName: 'pic.png' // <β€” Mandatory
});

// As plain base64:
imagesCollection.insert({
  file: 'base64str…',
  isBase64: true, // <β€” Mandatory
  fileName: 'pic.png', // <β€” Mandatory
  type: 'image/png' // <β€” Mandatory
});

For more expressive example see Upload demo app

Stream files

To display files you can use fileURL template helper or .link() method of FileCursor.

Template:

<template name='file'>
  <img src="{{imageFile.link}}" alt="{{imageFile.name}}" />
  <!-- Same as: -->
  <!-- <img src="{{fileURL imageFile}}" alt="{{imageFile.name}}" /> -->
  <hr>
  <video height="auto" controls="controls">
    <source src="{{videoFile.link}}?play=true" type="{{videoFile.type}}" />
    <!-- Same as: -->
    <!-- <source src="{{fileURL videoFile}}?play=true" type="{{videoFile.type}}" /> -->
  </video>
</template>

Shared code:

import { Meteor } from 'meteor/meteor';
import { FilesCollection } from 'meteor/ostrio:files';

const imagesCollection = new FilesCollection({collectionName: 'images'});
const videosCollection = new FilesCollection({collectionName: 'videos'});

if (Meteor.isServer) {
  // Upload sample files on server's startup:
  Meteor.startup(() => {
    imagesCollection.load('https://raw.githubusercontent.com/veliovgroup/Meteor-Files/master/logo.png', {
      fileName: 'logo.png'
    });
    videosCollection.load('http://www.sample-videos.com/video/mp4/240/big_buck_bunny_240p_5mb.mp4', {
      fileName: 'Big-Buck-Bunny.mp4'
    });
  });

  Meteor.publish('files.images.all', function () {
    return imagesCollection.find().cursor;
  });

  Meteor.publish('files.videos.all', function () {
    return videosCollection.find().cursor;
  });
} else {
  // Subscribe to file's collections on Client
  Meteor.subscribe('files.images.all');
  Meteor.subscribe('files.videos.all');
}

Client's code:

Template.file.helpers({
  imageFile() {
    return imagesCollection.findOne();
  },
  videoFile() {
    return videosCollection.findOne();
  }
});

For more expressive example see Streaming demo app

Download button

Template:

<template name='file'>
  <a href="{{file.link}}?download=true" download="{{file.name}}" target="_parent">
    {{file.name}}
  </a>
</template>

Shared code:

import { Meteor } from 'meteor/meteor';
import { FilesCollection } from 'meteor/ostrio:files';
const imagesCollection = new FilesCollection({collectionName: 'images'});

if (Meteor.isServer) {
  // Load sample image into FilesCollection on server's startup:
  Meteor.startup(function () {
    imagesCollection.load('https://raw.githubusercontent.com/veliovgroup/Meteor-Files/master/logo.png', {
      fileName: 'logo.png',
      meta: {}
    });
  });

  Meteor.publish('files.images.all', function () {
    return imagesCollection.find().cursor;
  });
} else {
  // Subscribe on the client
  Meteor.subscribe('files.images.all');
}

Client's code:

Template.file.helpers({
  fileRef() {
    return imagesCollection.findOne();
  }
});

For more expressive example see Download demo

FAQ:

  1. Where are files stored by default?: by default if config.storagePath isn't passed into Constructor it's equals to assets/app/uploads and relative to running script:
    • a. On development stage: yourDevAppDir/.meteor/local/build/programs/server. Note: All files will be removed as soon as your application rebuilds or you run meteor reset. To keep your storage persistent during development use an absolute path outside of your project folder, e.g. /data directory.
    • b. On production: yourProdAppDir/programs/server. Note: If using MeteorUp (MUP), Docker volumes must to be added to mup.json, see MUP usage
  2. Cordova usage and development: With support of community we do regular testing on virtual and real devices. To make sure Meteor-Files library runs smoothly in Cordova environment β€” enable withCredentials; enable {allowQueryStringCookies: true} and {allowedOrigins: true} on both Client and Server. For more details read Cookie's repository FAQ
  3. How to pause/continue upload and get progress/speed/remaining time?: see Object returned from insert method
  4. When using any of accounts packages - package accounts-base must be explicitly added to .meteor/packages above ostrio:files
  5. cURL/POST uploads - Take a look on POST-Example by @noris666
  6. In Safari (Mobile and Desktop) for DDP chunk size is reduced by algorithm, due to error thrown if frame is too big. Limit simultaneous uploads to 6 is recommended for Safari. This issue should be fixed in Safari 11. Switching to http transport (which has no such issue) is recommended for Safari. See #458
  7. Make sure you're using single domain for the Meteor app, and the same domain for hosting Meteor-Files endpoints, see #737 for details
  8. When proxying requests to Meteor-Files endpoint make sure protocol http/1.1 is used, see #742 for details

Awards:

Get Support:

Demo application:

Fully-featured file-sharing app

Related Packages:

Support Meteor-Files project:

Contribution:

  • Want to help? Please check issues for open and tagged as help wanted issues;
  • Want to contribute? Read and follow PR rules. All PRs are welcome on dev branch. Please, always give expressive description to your changes and additions.

Supporters:

We would like to thank everyone who support this project

meteor-files's People

Contributors

amos-whitewolf avatar bryanlimy avatar callmemb avatar coagmano avatar derwok avatar dr-dimitru avatar elewis33 avatar epaminond avatar exkazuu avatar gariest avatar harryadel avatar huevoncito avatar jankapunkt avatar jdmswong avatar kakadais avatar macrozone avatar make-github-pseudonymous-again avatar menelike avatar mikkelking avatar olivercoleman avatar paulincai avatar prinzhorn avatar rafaelcorreiapoli avatar rezarahemtola avatar rolljee avatar s-ol avatar salmanhasni avatar sophiabits avatar vtocco avatar xsyann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meteor-files's Issues

Duplicate headers received from server

In Chrome Browser:
Duplicate headers received from server
ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
Details:
The response from the server contained duplicate headers. This problem is generally the result of a misconfigured website or proxy. Only the website or proxy administrator can fix this issue.

Feature request

Little feature request. I think it would be helpful to have the ability to prevent auto upload. So we can render custom UI controllers for the upload and then manually call continue()

Add upload state property

It would be useful to support the state of the upload in the object returned from files.insert()

Perhaps name it state with its only values being:

  • active
  • paused
  • aborted
  • completed

That would be very helpful in styling the progress bar relative to the upload state, so users could easily see the status of their upload.

Client sets file location once, Server can access at will

My project is reading clients game log files and outputting results. I have client set location for a text log file for a game they play when they sign up. Currently only the upload occurs when client calls the upload. I want it to be so that once file location is defined/set then both client and server can access file passively without client having to explicitly call upload. So once client is logged in I would have access to file as a streaming read/write that can be open/called at any time. Is this currently possible and I am failing on way to implement or would this be possible as enhancement?
Thank you for reviewing.

Get FilesCollection instance by name

I was wondering if this was possible. Right now I'm working to get this package working in full compatibility with AutoForm and I only need to get instantiated objects of FilesCollection by their name. I can get the mongo collection instance with a package from dburles, but when I trigger the remove on the mongo collection instance, the files don't get deleted. I need the remove method from FilesCollection.

Sure an snippet of what I want to do will help:

// FilesCollection instance
Files = new FilesCollection({
    collectionName: 'files', // name of the collection
    allowClientCode: true, // Allow or forbid remove files from Client
    onBeforeUpload: function (file) {
        if (file.size <= 10485760 ) {
          return true;
        } else {
          return 'El fichero excede el tamaΓ±o mΓ‘ximo permitido (10 MB)';
        }
    },
    permissions: 0777,
    storagePath: path,

});

// Current removal method:

Files.remove(...).

// What I want to do:

getFilesCollection({collectionName: 'files'}).remove(...)

Thank you for this awesome package!

Upload pause not working

Hello,

I get the following client error when I try to pause a file upload:

TypeError: Cannot read property 'get' of undefined at Meteor.Files.Files.insert.Meteor.isClient.result.toggle (files.coffee:791)

files.coffee:791

...
          toggle: () ->
            if @onPause.get() then @continue() else @pause() 
...

This is how I call the funcion:

       this.insert;
       this.addFile = (files) => {
        ...

         this.insert = Documents.insert({
          ...
         });
      }

      this.togglePause = () => {
        if (this.insert !== undefined) {
          this.insert.toggle.call();
        }
      }

this.insert.onPause is returning false. Why @onpause is undefined?

Example of user permission checking function (protected attribute)

Great library! I'm almost done with my app thanks to you, but I'm trying to define a custom protected function for advanced permission checking and user() and userId remain undefined.

Maybe it's a bug. To be sure, could you add to the demo an example of a custom protected function using all parameters?

Thanks again!

".remove" sets the storagePath to null

If i remove a record with: Images.collection.remove({_id:id});

Everything works as expected. (The record is removed from the "Images" Collection.)
If a insert new files after that, they are added to the Collection and FS at 'local\build\programs\server\assets\app\uploads'
So, no problems here.

If i want to remove the record AND the file from the FS with: Images.remove({_id: id}); (same code expect this line)

Also, everything works as expected. (record and file from FS gets removed, no errors)

BUT, ALL FILES that i insert after that, are uploaded in an "undefined" folder at "local\build\programs\server\undefined" in opposite to the 'local\build\programs\server\assets\app\uploads' folder before.

If you get the output of the file records in Images.find({}).fetch(); the storagePath is null ('assets/app/uploads' before the remove) and the "path" is something like "undefined/6PTvaQYHdHJe9n6bj.jpg".

I have this problem on windows and on the ubuntu server that i host.

Images disappear after server restart

I am saving all my images in directory: storagePath: 'assets/uploads/avatars/' and after restart server directory with files disappear. All data still exist in collection but files are gone. Maybe I have to store images in another place?

Error removing image with versions

Im having an issue when trying to remove an image that has version, im getting the following error

Error invoking Method 'MeteorFileUnlink9b7534345192d71efbfeb0a333fe42deb50e466382219d2bf904a0220380f3ad': Internal server error [500]

When removing files without any version it wont happen.

Can't get logged user in 'protected' function

Hi,

I'm trying to add some security when downloading files but I can't get the user info inside the 'protected' function. My configuration looks like this:

Documents = new Meteor.Files({
  storagePath: "D:/temp",
  collectionName: 'documents',
  downloadRoute: '/doc',
  allowClientCode: true,
  chunkSize: 256*128,
  protected: (fileObj) => {
    console.log(fileObj);
    return true;
  }
});

The file is downloaded and I can get the info of the fileObj but I tried this.userId (undefined), this.user() -gives an TypeError.. has no method 'user'.

What am I doing wrong?

What template language do you use?

Hi,

can you tell me what template language / system you use in the examples in the README? Looks a lot like HAML and I'd love to try that out ;)

Thanks in advance

No Preview for files

Hi, I don't get any file prelisten or view here:

http://_.meteor.com/gt2uRGekimkrjRWhb

?

No compatible binary build found for this package

Hi,

I wanted to update my packages today and it seems that the Meteor-Files one (ostrio:files) is somehow broken currently (at least for me).
nocompatiblebinary

There might have occured an error in one of the later steps of publishing the build.

Small working sample

Hi,

I could not find an email address or other contact information so I am opening an issue to really ask a question. Is there a small working sample of Meteor-Files anywhere? The readme is overwhelming and in coffee so it's not great for new Meteor developers that may not know coffee. It would really help if there was just a small real working example of uploading a small file to FS somewhere.

pass meta to onBeforeUpload

Sometimes I need to do validations based on user input, e.g. the directory name which the uploaded file should be referenced to. In those cases I need to check permissions on onBeforeUpload, but since the meta obj is not available there is no way to determine the permission.

How would this be solved with this lib? Any chance to add meta as additional arg to onBeforeUpload call?

Thanks in advance.

How to use subversions

Hi,

I tried as below

const Images = new FilesCollection({
  ......
  onAfterUpload: function( fileRef ) {
    const cropName = fileRef.path + "__thumbnail__.jpg"
    Imagemagick.crop({
      srcPath: fileRef.path,
      dstPath: cropName,
      width: 200,
      height: 200,
      quality: 0.8,
      gravity: "Center"
    })
    const upd = {
      $set: {
        "versions.thumbnail" : {
          path: cropName,
          type: "image/jpeg",
          extension: "jpg"
        } 
      }
    }
    return Images.update( fileRef._id, upd )
  }
  ......
})

I could see the thumnail file generated on the same directory with original one.

on client side code

this.images().map(( image ) => {
  return (
    <li key={image._id}>  
      <img src={Images.link(image, "thumbnail")} />
    </li>
  )
})

'scr' attribute looks like "......id/thumbnail/id.jpg" but the image shown up is not a 200x200 thumbnail. It is just original one.

is it possible to update the metadata?

I am trying to update the metadata of an existing Images collection like this:
Images.collection.update(this._id, {$set: {'meta.big': !this.meta.big}});
'big' is a boolean.
but i get update failed: Access denied

my fault or impossible?

ROOT_URL and File Not Found :(

Hi,

I'm afraid I don't understand using ROOT_URL in this package. Please help, what is the correct way.

Example:
When I upload images in my dev system locally with ordinary:
meteor --port 3000
everything works as expected.

But when I want to change path with ROOT_URL to access same system for testing external access with:
ROOT_URL=http://palpinter.dlinkddns.com:3000 meteor --port 3000
I receive 'File Not Found :(' error message for all uploaded images.

And if change the port only:
meteor --port 3030
the result is the same, ''File Not Found :(' for all uploaded images.

How can I change ROOT_URL to access my uploaded images?

Thx
Pal

add package breaks app

i think something conflict with files package

W20150916-23:31:03.689(8)? (STDERR)
W20150916-23:31:03.690(8)? (STDERR) /Users/monsterstep/.meteor/packages/meteor-tool/.1.1.4.16s0drq++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150916-23:31:03.690(8)? (STDERR)                         throw(ex);
W20150916-23:31:03.690(8)? (STDERR)                               ^
W20150916-23:31:03.690(8)? (STDERR) TypeError: Object function (){                                                                                         // 253
W20150916-23:31:03.691(8)? (STDERR)         if( Object.prototype.toString.call(this) !== '[object Object]' &&                                      // 254
W20150916-23:31:03.691(8)? (STDERR)             Object.prototype.toString.call(this) !== '[object Array]'){                                        // 255
W20150916-23:31:03.691(8)? (STDERR)             return undefined;                                                                                  // 256
W20150916-23:31:03.691(8)? (STDERR)         }                                                                                                      // 257
W20150916-23:31:03.691(8)? (STDERR)         return this[Math.floor(Math.random() * this.length)];                                                  // 258
W20150916-23:31:03.691(8)? (STDERR)     } has no method 'arrayElement'
W20150916-23:31:03.691(8)? (STDERR)     at [object Object].self.phoneFormats (/Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/isopacks/npm-container/npm/node_modules/faker/lib/phone_number.js:16:25)
W20150916-23:31:03.691(8)? (STDERR)     at [object Object].self.phoneNumber (/Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/isopacks/npm-container/npm/node_modules/faker/lib/phone_number.js:5:38)
W20150916-23:31:03.691(8)? (STDERR)     at server/fixtures.coffee:25:25
W20150916-23:31:03.691(8)? (STDERR)     at server/fixtures.coffee:5:1
W20150916-23:31:03.691(8)? (STDERR)     at /Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/build/programs/server/boot.js:222:10
W20150916-23:31:03.691(8)? (STDERR)     at Array.forEach (native)
W20150916-23:31:03.692(8)? (STDERR)     at Function._.each._.forEach (/Users/monsterstep/.meteor/packages/meteor-tool/.1.1.4.16s0drq++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150916-23:31:03.692(8)? (STDERR)     at /Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/build/programs/server/boot.js:117:5
=> Exited with code: 8
W20150916-23:31:09.259(8)? (STDERR)
W20150916-23:31:09.259(8)? (STDERR) /Users/monsterstep/.meteor/packages/meteor-tool/.1.1.4.16s0drq++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150916-23:31:09.259(8)? (STDERR)                         throw(ex);
W20150916-23:31:09.259(8)? (STDERR)                               ^
W20150916-23:31:09.273(8)? (STDERR) TypeError: Object function (){                                                                                         // 253
W20150916-23:31:09.273(8)? (STDERR)         if( Object.prototype.toString.call(this) !== '[object Object]' &&                                      // 254
W20150916-23:31:09.273(8)? (STDERR)             Object.prototype.toString.call(this) !== '[object Array]'){                                        // 255
W20150916-23:31:09.273(8)? (STDERR)             return undefined;                                                                                  // 256
W20150916-23:31:09.274(8)? (STDERR)         }                                                                                                      // 257
W20150916-23:31:09.274(8)? (STDERR)         return this[Math.floor(Math.random() * this.length)];                                                  // 258
W20150916-23:31:09.274(8)? (STDERR)     } has no method 'arrayElement'
W20150916-23:31:09.274(8)? (STDERR)     at [object Object].self.phoneFormats (/Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/isopacks/npm-container/npm/node_modules/faker/lib/phone_number.js:16:25)
W20150916-23:31:09.274(8)? (STDERR)     at [object Object].self.phoneNumber (/Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/isopacks/npm-container/npm/node_modules/faker/lib/phone_number.js:5:38)
W20150916-23:31:09.274(8)? (STDERR)     at server/fixtures.coffee:25:25
W20150916-23:31:09.275(8)? (STDERR)     at server/fixtures.coffee:5:1
W20150916-23:31:09.275(8)? (STDERR)     at /Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/build/programs/server/boot.js:222:10
W20150916-23:31:09.275(8)? (STDERR)     at Array.forEach (native)
W20150916-23:31:09.275(8)? (STDERR)     at Function._.each._.forEach (/Users/monsterstep/.meteor/packages/meteor-tool/.1.1.4.16s0drq++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150916-23:31:09.275(8)? (STDERR)     at /Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/build/programs/server/boot.js:117:5
=> Exited with code: 8
W20150916-23:31:14.633(8)? (STDERR)
W20150916-23:31:14.633(8)? (STDERR) /Users/monsterstep/.meteor/packages/meteor-tool/.1.1.4.16s0drq++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150916-23:31:14.633(8)? (STDERR)                         throw(ex);
W20150916-23:31:14.634(8)? (STDERR)                               ^
W20150916-23:31:14.648(8)? (STDERR) TypeError: Object function (){                                                                                         // 253
W20150916-23:31:14.648(8)? (STDERR)         if( Object.prototype.toString.call(this) !== '[object Object]' &&                                      // 254
W20150916-23:31:14.648(8)? (STDERR)             Object.prototype.toString.call(this) !== '[object Array]'){                                        // 255
W20150916-23:31:14.648(8)? (STDERR)             return undefined;                                                                                  // 256
W20150916-23:31:14.648(8)? (STDERR)         }                                                                                                      // 257
W20150916-23:31:14.649(8)? (STDERR)         return this[Math.floor(Math.random() * this.length)];                                                  // 258
W20150916-23:31:14.649(8)? (STDERR)     } has no method 'arrayElement'
W20150916-23:31:14.649(8)? (STDERR)     at [object Object].self.phoneFormats (/Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/isopacks/npm-container/npm/node_modules/faker/lib/phone_number.js:16:25)
W20150916-23:31:14.649(8)? (STDERR)     at [object Object].self.phoneNumber (/Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/isopacks/npm-container/npm/node_modules/faker/lib/phone_number.js:5:38)
W20150916-23:31:14.649(8)? (STDERR)     at server/fixtures.coffee:25:25
W20150916-23:31:14.649(8)? (STDERR)     at server/fixtures.coffee:5:1
W20150916-23:31:14.649(8)? (STDERR)     at /Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/build/programs/server/boot.js:222:10
W20150916-23:31:14.649(8)? (STDERR)     at Array.forEach (native)
W20150916-23:31:14.649(8)? (STDERR)     at Function._.each._.forEach (/Users/monsterstep/.meteor/packages/meteor-tool/.1.1.4.16s0drq++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150916-23:31:14.649(8)? (STDERR)     at /Volumes/Data/dev/nexushubs/lawflow/lawflow-system/.meteor/local/build/programs/server/boot.js:117:5

TypeError: Cannot read property 'indexOf' of undefined

Hi,

when I tried upload with this:

      Images.insert
        file: file
        onUploaded: (error, fileObj) ->
          if error
            alert 'Error during upload: ' + error
          else
            alert 'File "' + fileObj.name + '" successfully uploaded'
          return
        streams: 'dynamic'
        chunkSize: 'dynamic'

TypeError: Cannot read property 'indexOf' of undefined
    at FilesCollection.getExt (files.coffee:550)
    at new UploadInstance (files.coffee:907)
    at FilesCollection.insert (files.coffee:851)
    at ViewModel.Template.SignUp.viewmodel.uploadPicture (sign-up.coffee:55)

Of course the 'file' is exist. Its name: 'img.png'

Thx
Pal

How to display files on meteor 1.3 + reactjs

Hi,

I can use fileURL template helper on blaze.
If i use meteor 1.3 + reactjs, how can I display files?

I tried like below
src=${image._downloadRoute}/${image._id}.${image.extension}

Thank you

Service Unavailable when using ?play=true in the demo

Hi,
thank you for this great plugin!

The only thing that doesn't work for me is the ?play=true streaming (with an mp3 file). The download option works but the play option returns "Service Unavailable" (Screenshot of the demo can be found attached).

Could you please give me a hint why this is happening? Thanks!
serviceunavailable_503

Mach error on upload

thanks for the fast fix of my last issue! Now I'm getting an error when uploading a file. Not sure if this is a bug or some misconfiguration on my side.

Exception while invoking method 'MeteorFileWrite27cbfcbe172a3d9bf03834c002d75f0926d0fa16f28594a4ac80e587325df05f' Error: Match error: Failed Match.OneOf or Match.Optional validation
    at checkSubtree (packages/check/match.js:244:1)
    at check (packages/check/match.js:32:1)
    at [object Object].Files._methods.(anonymous function) (packages/ostrio:files/files.coffee:266:9)
    at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1)
    at packages/ddp/livedata_server.js:648:1
    at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
    at packages/ddp/livedata_server.js:647:1
    at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
    at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1)
    at packages/ddp/livedata_server.js:546:1
Sanitized and reported to the client as: Match failed [400]

Exception from sub Images

Hi

I got this kind of exception

Meteor.Files Debugger: [find(undefined)]
I20160409-16:15:55.655(2)? Exception from sub Images id GngR84PRRRtf9ZjhC Error: Match error: Failed Match.OneOf, Match.Maybe or Match.Optional validation
I20160409-16:15:55.655(2)?     at check (packages/check.js:138:15)
I20160409-16:15:55.655(2)?     at Files.Meteor.Files.Files.find (packages/ostrio_files/files.coffee:695:5)
I20160409-16:15:55.656(2)?     at Subscription._handler (server/init.js:10:26)
I20160409-16:15:55.656(2)?     at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1704:12)
I20160409-16:15:55.656(2)?     at Subscription._runHandler (packages/ddp-server/livedata_server.js:1026:17)
I20160409-16:15:55.656(2)?     at Session._startSubscription (packages/ddp-server/livedata_server.js:845:9)
I20160409-16:15:55.656(2)?     at Session.sub (packages/ddp-server/livedata_server.js:617:12)
I20160409-16:15:55.656(2)?     at packages/ddp-server/livedata_server.js:551:43
I20160409-16:15:55.657(2)? Sanitized and reported to the client as: Match failed [400]

thanks for help
Best Regards
Michal

Large file upload performance?

Hi Meteor-Files team,

Any solution for upload a file ~10GB via DDP without RAM dependence?
I'm building a storage service and allow user upload file(s) in any size.

can find uploaded images in folder

Hi,
I'm using version 1.2.1 on osx 10.11(el capitan) and I cant find my uploaded images on FS. debug says
Meteor.Files Debugger: The file tennis-icon.png (binary) was saved to assets/app/uploads/uploadedFiles/knRbZlNgtDVFEuFrp.png but this kind of path doest even exist
Please help me :) thanks
Best Regards

v1.4.2 uploading large files doesn't work anymore ?

Hi,

Firstly thanks for this new version. We can now play videos on all browsers. Good work and thank you for your reactivity !

Unfortunately with this new version when i try to upload a small file, it works perfectly but if i try with a larger file (in my case more than 300Mo but I will try other size to test) the upload process freeze, no chunk is sent to the server.
There was no problem with the previous version.

I can't test it with your live demo because we can't upload a file larger than 128Mo.

Playing video with "?play=true"

Thank you for this good meteor package.

When I upload a video file and I try to play it on Google Chrome (Desktop), it works perfectly but with an other browser, for example Mozilla Firefox, you can just read the first few seconds an it stops. And with Safari it just does not work.

You can experiment that with the Meteor-Files live demo. Upload the demo video file of the VideoJS website (playing well on all the browser mobile/desktop).

Thx.

How to add additional fields to collection.doc and not to collection.doc.meta

I need to add additional data to the created document. Currently this is only possible trough config.meta. My collection is created like:

const FooFiles = new FilesCollection({
  collectionName: 'FooFiles',
});

const MetaSchema = new SimpleSchema({
  fooId: {
    type: String,
  },
});

const FooFilesSchema = new SimpleSchema({
  ...FooFiles.schema,
  meta: {
    type: MetaSchema,
  },
});

FooFiles.collection.attachSchema(FooFilesSchema);

note: imho this is the proper way to attach schema to a collection, the current documentation does not follow collection2/simple schema guidelines

What I really need is to be in full control of the document because I need to set the Index on fooId e.g.

Update: Of course indexes can be applied to nested fields which solves this scenario

  fooId: {
    type: String,
    index: true,
  },

I love this lib, it has everything I need and it works very well. This is the only feature I miss a lot, would be quiet happy about a clean and straightforward solution.
Maybe a second object like config.doc could help here. Later on this could just be merged with existing data like {...config.doc, ...currentInsertedObj}, validation should be done trough SimpleSchema.

React Native upload image/video to meteor server

Hello there, i try to upload image in from react-native to meteor using base64 encode for image and its working, but i would like to know if you have idea how to upload from external like react-native to Meteor Server with file path. i know that in heruko they use ephemeral filesystem, so i can use my own server to upload video/audio? any codes in react-native to meteor? i use DDP Client

Thanks

How to get a file names?

Hey. Anybody can tell, how to get the file name and simply insert it into the src? I read the documentation and I'm probably doing something wrong. Because in the collection, I see a lot of things, but I don't see the original file name.

PhotosCollection.load(photoLink, {
      fileName: `${id}.png`,
});

but it did not help, files are still named differently.

When I tried to make ImagesCollection.findOne ({_ id: id}) link (); I got links to files without the extension. The path to the file at the same time look strange. Something like
http://localhost:3000/public/photos/photos/Gd99qerb3e4y6Ee3m/original/Gd99qerb3e4y6Ee3m

My collection settings

PhotosCollection = new FilesCollection({
    storagePath: process.env.PWD + '/public/photos',
    downloadRoute: '/public/photos',
    collectionName: 'photos',
    allowClientCode: false,
    cacheControl: 'public, max-age=31536000',
    onBeforeUpload(file) {
        if (file.size <= 20971520 && /png|jpg|jpeg/i.test(file.ext)) {
            return true;
            } else {
            return 'Please upload image, with size equal or less than 20MB';
        }
    },
    downloadCallback(fileObj) {
        if (this.params.query.download == 'true') {
            // Increment downloads counter
            PhotosCollection.update(fileObj._id, {$inc: {'meta.downloads': 1}});
        }
        return true;
    }
});

I just want to get an array of names of files and display them on the client, it is possible even without a path. I write them by myself ;)

ReferenceError: check is not defined with Meteor 1.1.0.2

I can't start meteor because of the following error:

ReferenceError: check is not defined
    at new Files (packages/ostrio:files/files.coffee:147:5)
    at Files.allow.insert (packages/app-filestore/lib/files.js:1:1)
    at /home/jokke/code/projects/tagfs/.meteor/local/build/programs/server/packages/app-filestore.js:28:4
    at /home/jokke/code/projects/tagfs/.meteor/local/build/programs/server/packages/app-filestore.js:92:3
    at /home/jokke/code/projects/tagfs/.meteor/local/build/programs/server/boot.js:222:10
    at Array.forEach (native)
    at Function._.each._.forEach (/home/jokke/.meteor/packages/meteor-tool/.1.1.3.4sddkj++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
    at /home/jokke/code/projects/tagfs/.meteor/local/build/programs/server/boot.js:117:5

Example for AWS S3 Integration

I have seen thi is in the Roadmap, and I just want to give it a πŸ‘ since it would be a very common use case (even more than dropbox I think).
Good work on this package :)

cant show inserted image

hi,

I use thus code

    {{#if currentFile}}
        Uploading <b>{{currentFile.file.name}}</b>:
        <span id="progress">{{progress}}%</span>
        <img src="{{fileURL imageFile}}" alt="{{imageFile.name}}"/>
    {{else}}
        <input id="fileInput" type="file"/>
    {{/if}}
    <hr>

and that in template helper

   imageFile: function () {
        return InterestIcons.collection.findOne({});
    }

and cant see the uploaded image

Best regards

Support for Angular?

I would like to use Meteor-Files with AngularJS (files list, progress bar, message, etc.)
Can your team support or planning for it?

My bad English :)
Thanks.

UPDATE:
I've found settings obj in Insert API.

How can I get the height and width of uploaded images?

This code prints the image's width and height only after a timeout.

                    onUploaded: function (error, fileRef) {

                        var img = new Image;
                        img.src = Blaze._globalHelpers['fileURL'](fileRef);
                        setTimeout(function () {
                            console.log("5 sec delay:", img.height, " x ", img.width);
                        }, 5000);
                        console.log("First try: ", img.height, " x ", img.width);

Is there a way to get this data without using a timeout?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.