• Stars
    star
    1,111
  • Rank 41,780 (Top 0.9 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿš€ Upload files via DDP or HTTP to โ˜„๏ธ Meteor server FS, AWS, GridFS, DropBox or Google Drive. Fast, secure and robust.

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

More Repositories

1

mail-time

๐Ÿ“ฎ Bulletproof email queue on top of NodeMailer for a single and multi-server setup
JavaScript
125
star
2

ostrio

โ–ฒ Web services for JavaScript, Angular.js, React.js, Vue.js, Meteor.js, Node.js, and other JavaScript-based websites, web apps, single page applications (SPA), and progressive web applications (PWA). Our services: Pre-rendering, Monitoring, Web Analytics, WebSec, and Web-CRON
61
star
3

ostrio-neo4jdriver

Most advanced and efficient Neo4j REST API Driver, with support of https and GrapheneDB
CoffeeScript
54
star
4

Meteor-Files-Demos

Demos for ostrio:files package
JavaScript
52
star
5

ostrio-Neo4jreactivity

Meteor.js Neo4j database reactivity layer
CoffeeScript
51
star
6

Meteor-logger

๐Ÿงพ Meteor isomorphic logger. Store application logs in File (FS), MongoDB, or print in Console
JavaScript
51
star
7

meteor-cookies

๐Ÿช Isomorphic bulletproof cookie functions for client and server
JavaScript
41
star
8

Meteor-flow-router-meta

Reactive meta tags, JavaScript links and CSS for meteor within flow-router-extra
JavaScript
39
star
9

Meteor-Leaderboard-Neo4j

Neo4j database powered standard --example Leaderboard Meteor app
JavaScript
37
star
10

Meteor-Template-helpers

Template helpers for Session, logical operations and debug
JavaScript
35
star
11

jazeee-meteor-spiderable

Fork of Meteor Spiderable with longer timeout, caching, better server handling
JavaScript
33
star
12

spiderable-middleware

๐Ÿค– Prerendering for JavaScript powered websites. Great solution for PWAs (Progressive Web Apps), SPAs (Single Page Applications), and other websites based on top of front-end JavaScript frameworks
JavaScript
32
star
13

josk

๐Ÿค– Node.js setInterval for multi-server setup, managed via MongoDB
JavaScript
29
star
14

Meteor-flow-router-title

Change document.title on the fly within flow-router
JavaScript
24
star
15

Meteor-logger-file

๐Ÿ”– Meteor Logging: Store application log messages into file (FS)
JavaScript
24
star
16

Meteor-logger-mongo

๐Ÿƒ Meteor Logging: Store application log messages in MongoDB
JavaScript
22
star
17

Meteor-Mailer

๐Ÿ“ฎ Bulletproof email queue on top of NodeMailer with support of multiple clusters and servers setup
21
star
18

request-extra

โšก๏ธ Extremely stable HTTP request module built on top of libcurl with retries, timeouts and callback API
JavaScript
21
star
19

neo4j-fiber

๐Ÿ‘จโ€๐Ÿ”ฌ Neo4j REST API Driver, with support of https and all DB's features
JavaScript
21
star
20

Meteor-logger-console

๐Ÿ–ฅ Meteor Logging: Print Client's log messages into Server's console with nice highlighting
JavaScript
20
star
21

Meteor-root

[Server] โ˜„๏ธ Get path on a server where Meteor application is currently running
JavaScript
19
star
22

Meteor-Files-Demo

Demo application for ostrio:files package
JavaScript
17
star
23

Uniq.site

An unique name, domain and brand generator
CoffeeScript
17
star
24

Meteor-CRON-jobs

๐Ÿƒโ€โ™‚๏ธ๐Ÿค– Task and jobs runner. With support of clusters or multiple meteor.js instances.
15
star
25

Client-Storage

๐Ÿ—„ Bulletproof persistent Client storage, works with disabled Cookies and/or localStorage
JavaScript
15
star
26

Meteor-Internationalization

๐Ÿ™Š Super-Lightweight and fast i18n isomorphic driver for Meteor with support of placeholders.
JavaScript
14
star
27

ostrio-analytics

๐Ÿ“Š Visitor's analytics tracking code for ostr.io service
JavaScript
14
star
28

fps-meter

Efficient and accurate FPS meter, with minimalistic UI
JavaScript
13
star
29

meteor-files-website

File sharing PWA. Upload and share at files.veliov.com
JavaScript
13
star
30

meteor-user-status

Reactively track user's online, offline, and idle statuses
JavaScript
11
star
31

Meteor-iron-router-title

Reactive page title for meteor within iron-router
CoffeeScript
8
star
32

Meteor-Client-Storage

Bulletproof Client storage functions for Meteor, localStorage with fall-back to Cookies
JavaScript
7
star
33

Meteor-iron-router-meta

Change meta tags on the fly within iron-router
CoffeeScript
6
star
34

Meteor-UIBlocker

๐Ÿ–ฅ UI blocker and simple loading spinner for Meteor apps
CSS
5
star
35

Meteor-iron-router-protected

Create protected and meteor-roles restricted routes within iron-router
CSS
5
star
36

meteor-base64

Highly efficient isomorphic Base64 encoding and decoding with support of WebWorkers
JavaScript
5
star
37

meteor-python-files

File Uploads to Meteor Server in Python (meteor pyfiles)
Python
5
star
38

neo4j-demo

Demo application for Neo4j-fiber package
JavaScript
4
star
39

meteor-snippets

Tutorials, demos, tricks'n tips, code snippets for Meteor.js โ˜„๏ธ
JavaScript
4
star
40

Flow-Router-Demos

Demo apps for Flow-Router packages
HTML
3
star
41

meteor-aes-crypto

๐Ÿ” Simplified isomorphic API for AES cipher by CryptoJS
JavaScript
3
star
42

JavaScript-Objects-Extensions-for-Meteor

Useful JavaScript Objects Extensions for Meteor
JavaScript
3
star
43

iron-router-helpers-for-Meteor

An iron-router helpers for quickly adding classnames to your active navigation elements.
JavaScript
3
star
44

meteor-base64-replacement

"Enhanced Performance" base64 package for Meteor
JavaScript
2
star
45

instagram-node

Simple Instagram driver for Meteor (NPM)
JavaScript
1
star
46

best-practices

Software development best practices
JavaScript
1
star
47

meteor-i18n-library

Internationalization and localization (i18n & l10n) for Meteor
CoffeeScript
1
star
48

supporters

๐Ÿ“‹ The list of supporters and sponsors
1
star
49

careers

Job openings within veliovgroup
1
star