Code Monkey home page Code Monkey logo

meteor-autoform-file's Introduction

support support Mentioned in Awesome ostrio:files GitHub stars

Autoform File

# meteor@>=1.9
meteor add ostrio:autoform-files

# meteor@<1.9
meteor add ostrio:[email protected]

Description

Upload and manage files with autoForm via ostrio:files. This package was ported from yogiben:autoform-file to use with ostrio:files instead of the already deprecated CollectionFS.

Quick Start:

  1. Install meteor add ostrio:autoform-files
  2. Install meteor add ostrio:files, if not yet installed
  3. Add this config to simpl-schema NPM package (depending of the language that you are using):
SimpleSchema.setDefaultMessages({
  initialLanguage: 'en',
  messages: {
    en: {
      uploadError: '{{value}}', //File-upload
    },
  }
});
  1. Create your Files Collection (See ostrio:files)
import { Meteor } from 'meteor/meteor';
import { FilesCollection } from 'meteor/ostrio:files';

const imagesCollection = new FilesCollection({
  collectionName: 'images',
  allowClientCode: true, // Required to let you remove uploaded file
  onBeforeUpload(file) {
    // Allow upload files under 10MB, and only in png/jpg/jpeg formats
    if (file.size <= 10485760 && /png|jpg|jpeg/i.test(file.ext)) {
      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', () => {
    return imagesCollection.collection.find({});
  });
}

Note: If you don't use Mongo Collection instances (dburles:mongo-collection-instances), then the imagesCollection variable must be attached to Global scope. And has same name (case-sensitive) as collectionName option passed into FilesCollection#insert({collectionName: 'images'}) method, images in our case.

To start using dburles:mongo-collection-instances simply install it:

meteor add dburles:mongo-collection-instances
  1. Define your schema and set the autoform property like in the example below
Schemas = {};
Posts = new Meteor.Collection('posts');
Schemas.Posts = new SimpleSchema({
  title: {
    type: String,
    max: 60
  },
  picture: {
    type: String,
    autoform: {
      afFieldInput: {
        type: 'fileUpload',
        collection: 'images',
        uploadTemplate: 'uploadField', // <- Optional
        previewTemplate: 'uploadPreview', // <- Optional
        insertConfig: { // <- Optional, .insert() method options, see: https://github.com/veliovgroup/Meteor-Files/blob/master/docs/insert.md
          meta: {},
          isBase64: false,
          transport: 'ddp',
          chunkSize: 'dynamic',
          allowWebWorkers: true
        }
      }
    }
  }
});

Posts.attachSchema(Schemas.Posts);

The collection property must be the same as name of your FilesCollection (case-sensitive), images in our case.

Generate the form with {{> quickform}} or {{#autoform}} e.g.:

Insert mode:

{{> quickForm id="postsInsertForm" collection="Posts" type="insert"}}
<!-- OR -->
{{#autoForm id="postsInsertForm" collection="Posts" type="insert"}}
  {{> afQuickField name="title"}}
  {{> afQuickField name="picture"}}
  <button type="submit" class="btn btn-primary">Insert</button>
{{/autoForm}}

<!-- OR with .insert() method options -->
<!-- See: https://github.com/veliovgroup/Meteor-Files/wiki/Insert-(Upload) -->
{{#autoForm id="postsInsertForm" collection="Posts" type="insert"}}
  {{> afQuickField name="title"}}
  {{> afQuickField name="picture" transport="http" allowWebWorkers="false"}}
  <button type="submit" class="btn btn-primary">Insert</button>
{{/autoForm}}

Update mode:

{{#if Template.subscriptionsReady }}
  {{> quickForm id="postsUpdateForm" collection="Posts" type="update" doc=getPost}}
{{/if}}
<!-- OR -->
{{#if Template.subscriptionsReady }}
  {{#autoForm id="postsUpdateForm" collection="Posts" type="update" doc=getPost}}
    {{> afQuickField name="title"}}
    {{> afQuickField name="picture"}}
    <button type="submit" class="btn btn-primary">Update</button>
  {{/autoForm}}
{{/if}}

Autoform should be wrapped in {{#if Template.subscriptionsReady }} which makes sure that template level subscription is ready. Without it the picture preview won't be shown. You can see update mode example here.

Accept configuration

Usage

You can configure the file selector, to only allow certain types of files using the accept property:

Schemas.Posts = new SimpleSchema({
  title: {
    type: String,
    max: 60
  },
  picture: {
    type: String,
    autoform: {
      afFieldInput: {
        type: 'fileUpload',
        collection: 'images',
        accept: 'image/*' // or use explicit ext names like .png,.jpg
      }
    }
  }
});

The accept values works makes use of the native HTML accept attribute. Read more at the MDN documentation.

Please read the section on custom upload templates and how to integrate configs like accept to your custom template.

Multiple images

Multiple images — not fully supported yet

If you want to use an array of images inside you have to define the autoform on on the schema key

Schemas.Posts = new SimpleSchema({
  title: {
    type: String,
    max: 60
  },
  pictures: {
    type: Array,
    label: 'Choose file' // <- Optional
  },
  'pictures.$': {
    type: String,
    autoform: {
      afFieldInput: {
        type: 'fileUpload',
        collection: 'images'
      }
    }
  }
});

Custom file preview

Your custom file preview template data context will be:

  • file - fileObj instance
({
  picture: {
    type: String,
    autoform: {
      afFieldInput: {
        type: 'fileUpload',
        collection: 'images',
        previewTemplate: 'myFilePreview'
      }
    }
  }
});
<template name="myFileUpload">
  <a href="{{file.link}}">{{file.original.name}}</a>
</template>

Custom upload template

Your custom file upload template data context will be:

  • file - FS.File instance
  • progress
  • status
  • config an object containing several configs to upload behavior, such as accept
  • Other fields from FileUpload instance
({
  picture: {
    type: String,
    autoform: {
      afFieldInput: {
        type: 'fileUpload',
        collection: 'images',
        uploadTemplate: 'myFileUpload'
      }
    }
  }
});
<template name="myFileUpload">
  {{#with progress}}
    <!-- if there is a progress present, we can use it to determine the upload progress -->
    <progress value="{{this.get}}" max="100"></progress>
  {{/with}}
  {{#with file}}
    <!-- if there is a file present, we have a file selected for upload -->
    <span>Uploading {{this.name}}</span>
  {{else}}
     <!-- otherwise we provide the upload -->
     <input data-files-collection-upload class="form-control af-file-upload-capture" type="file" accept="{{config.accept}}" />
  {{/if}}
</template>

Note on upload configs:

If you pass any config, like accept your upload data won't be falsy anymore, so you should update your template to the example above and check for each of the given properties. This is however backwards-compatible and will not break your older templates if you don't need any of the upload config introduced in > 2.1.4 releases.

Support this project:

meteor-autoform-file's People

Contributors

aposidelov avatar bastiaanterhorst avatar captainn avatar christianbundy avatar dr-dimitru avatar harryadel avatar hosseinagha avatar jankapunkt avatar jfols avatar markleiber avatar martunta avatar mohammedessehemy avatar mpowaga avatar mrauhu avatar neobii avatar peernohell avatar pfmziota avatar yogiben 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

meteor-autoform-file's Issues

Syntax error in older browser + Phantom.js + Prerender.io

The latest version causes a syntax error bug. It also prerendering on prerender.io and probably with spiderable as well.

I had it on the 1.3.5.1 and now on 1.4.4.1 the issue is still present. I was on abernix:standard-minifier-js but moved to latest [email protected]

For me the problem is solved by going back one release 1.0.11. I could reproduce the bug easily in version 19 of firefox. I was mostly interested in fixing the prerender issues and just needed an old enough browser. I don't know how many browser version are affected.

But if anyone encounters the same, you can fix it by locking to the older version.

Default insertConfig chunksize and streams are NaN

Hey @dr-dimitru ,

I am out of knowledge here. While going through the codeof PR #56 using the debugger I found a strange behavior: When there is no insertConfig in the schema, the values of chunkSize and streams are always NaN. So I checked the part where the insertConfig is being built. I am totally unsure about these lines:

  this.insertConfig    = Object.assign({}, this.data.atts.insertConfig || {});
  delete this.data.atts.insertConfig;
  this.insertConfig    = Object.assign(this.insertConfig, _.pick(this.data.atts, Object.keys(defaultInsertOpts))); 

Why it is picking from data.atts? It results always in this.insertConfig being {} but this will trigger the condition of the next two lines:

  if (!isNaN(this.insertConfig.streams) || this.insertConfig.streams !== 'dynamic') {
    this.insertConfig.streams = parseInt(this.insertConfig.streams);
  }
  if (!isNaN(this.insertConfig.chunkSize) || this.insertConfig.chunkSize !== 'dynamic') {
    this.insertConfig.chunkSize = parseInt(this.insertConfig.chunkSize);
  }

because on {} these conditions are always true and parseInt(undefined) creates NaN to steams and chunksize are always NaN for empty insertConfig.

Is this intended? I doubt, because the meteor files wiki defines their types as {Number|dynamic}.

My proposal would be to either remove the _.pick (which also removes the dependency to underscore 👍) or to add a check in the conditionals for streams or chunkSize being not undefined.

What do you think?

Syntax Error when trying to deploy with Meteor Up

Hey there, not sure if this is related #21, but I am having issues deploying to digital ocean using Meteor Up. (I'm using meteor version 1.4.3.2)

$ mup deploy
Building App Bundle Locally
Errors prevented bundling:
While minifying app code:
packages/minifyStdJS_plugin.js:113:28: UglifyJS minification error: 

SyntaxError: Unexpected token: punc ()) at
packages/ostrio_autoform-files/lib/client/fileUpload.js line 16

within packages/ostrio_autoform-files.js (line: 195, col: 25, pos: 18455):

this.collectionName = () => {

at maybeThrowMinifyErrorBySourceFile (packages/minifyStdJS_plugin.js:113:28)
at packages/minifyStdJS_plugin.js:145:9
at Array.forEach (native)
at UglifyJSMinifier.processFilesForBundle
(packages/minifyStdJS_plugin.js:130:9)



=> Build Error. Check the logs printed above.
Error: build-error
    at ChildProcess.<anonymous> (/usr/local/lib/node_modules/mup/lib/modules/meteor/build.js:46:16)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

I believe my mup.js file is set up correctly:

module.exports = {
  servers: {
    one: {
      // TODO: set host address, username, and authentication method
      host: '138.197.101.26',
      username: 'root',
      password: '*******'
    }
  },

  meteor: {
    // TODO: change app name and path
    name: 'AnnaLublina',
    path: '.',
    volumes: {
      '/images':'/images'
    },

    servers: {
      one: {},
    },

    buildOptions: {
      serverOnly: true,
    },

    env: {
      ROOT_URL: 'http://138.197.101.26',
      MONGO_URL: 'mongodb://localhost/meteor',
    },

    docker: {
      // change to 'kadirahq/meteord' if your app is not using Meteor 1.4
      image: 'abernix/meteord:base',
      // imagePort: 80, // (default: 80, some images EXPOSE different ports)
    },

    // This is the maximum time in seconds it will wait
    // for your app to start
    // Add 30 seconds if the server has 512mb of ram
    // And 30 more if you have binary npm dependencies.
    deployCheckWaitTime: 60,

    // Show progress bar while uploading bundle to server
    // You might need to disable it on CI servers
    enableUploadProgressBar: false
  },

  mongo: {
    port: 27017,
    version: '3.4.1',
    servers: {
      one: {}
    }
  }
};

And my collection setup:

Images = new FilesCollection({
  collectionName: 'Images',
  storagePath: '../images',
  allowClientCode: true, // Required to let you remove uploaded file
  permissions: 0774,
	parentDirPermissions: 0774,
  onBeforeRemove: function (cursor) {
    if (this.userId) {
      var user = this.user();
      if (Roles.userIsInRole(user, 'admin')) {

        var imgId = cursor._selector;
        var project = Projects.findOne({pictures: {$in: [imgId]}});
        var p_id = project._id;
        Projects.update({"_id": p_id}, {"$pull": {"pictures": imgId}});
        return true;
        
      }
    }
    return false;
  }
});

Any ideas as to what may be going wrong?

Update mode example

Here is an example how to implement autoform with update mode & upload field. Critical place is that autoform should be wrapped in {{#if Template.subscriptionsReady }} which makes sure that template level subscription is ready. Without it the picture preview won't be shown. Also to make upper {{#if}} to be worked the template level subscription should be used (this.subscribe instead of Meteor.subscribe)

EditProductForm.js

Template.EditProductForm.onCreated(function() {    
    var self = this;        
    self.autorun(function() {   
        var id = FlowRouter.getParam('id');            
        self.subscribe('products.one', id);        
    });
});

Template.EditProductForm.helpers({
    getProduct() {
        var id = FlowRouter.getParam('id');
        var product = ProductsCollection.findOne(id);        
        return product;
    }
});

EditProductForm.html

<template name="EditProductForm">
    <div class="container">
        <div class="row">       
            {{#if Template.subscriptionsReady }}    
                {{#autoForm type="update" doc=getProduct collection=ProductsCollection  id="EditProductForm"}}
                    {{> afQuickField name='title'}}
                    {{> afQuickField name='desc'}}
                    {{> afQuickField name='priceAmount'}}
                    {{> afQuickField name='tags'}}
                    {{> afQuickField name='picture'}}     
                    <button type="submit" class="btn btn-primary btn-update">Update</button>
                    <button type="submit" class="btn btn-primary btn-delete">Delete</button>
                {{/autoForm}}
            {{/if}}
        </div>
    </div>
</template>

and server-side code

Meteor.publish('products.one', function(id) {       
    var product = ProductsCollection.find({_id: id});   
    var pictureId = product.fetch()[0].picture; 
    return [product, Images.find({_id: pictureId}).cursor]; 
});

Adding hooks

I have a suggestion:

I am still using this and I came to some limits I'd like to solve with some hooks:

picture: {
  type: String,
  autoform: {
    afFieldInput: {
      type: 'fileUpload',
      collection: 'Images',
      hooks: {
        onProgress: () => {}, // while in progress
        onComplete: () => {}, // progress === 100%
        onError: err => {}, // there was an upload error
        onRemove: fileId => {}, // user wants to delete the uploaded file
        onRemoved: () => {}, // the file has been removed
      }
    }
  }
}

The reasons are simple:

  • disable form submit/cancel until file has been uploaded
  • let users remove their uploaded file by using a custom Meteor method (because the default remove is disabled)
  • custom way of communicating upload errors to the user

Error on update forum

I am using the latest build of all items. The upload with autoform works like a dream, but updates throws this:
Error: Unexpected object in htmljs in toText: [object Object]
at HTMLVisitorSubtype.visitObject (htmljs.js?hash=c52d96e73a36896980b68a9b66c659292f8e393f:292)
at HTMLVisitorSubtype.visit (htmljs.js?hash=c52d96e73a36896980b68a9b66c659292f8e393f:113)
at Object.HTML.toText (htmljs.js?hash=c52d96e73a36896980b68a9b66c659292f8e393f:668)
at Blaze._toText (blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:2468)
at Object.Blaze._toText (client.coffee:100)
at Blaze.View.updateAttributes (template.coffee:1)
at blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:1934
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3769)
at blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:1932
at Object.Blaze._withCurrentView (blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:2271)

The schema is also very basic:
const Categories = new SimpleSchema({
category: {
type: String,
label: "Category"
},
createdAt: {
type: Date,
label: "Created on",
autoValue: function() {
return new Date()
}
},

picture: {
type: String,
autoform: {
afFieldInput: {
type: 'fileUpload',
collection: 'Images',
insertConfig: { // <- Optional, .insert() method options, see: https://github.com/VeliovGroup/Meteor-Files/wiki/Insert-(Upload)
meta: {},
isBase64: false,
transport: 'ddp',
streams: 'dynamic',
chunkSize: 'dynamic',
allowWebWorkers: true
}
}
}
}
});

Publish?

Can you publish this or is something missing?

Cheers

autoform dependency to 6.0.0

could you please update and test your package to work with the newely released autoform 6.0.0 package?

thanks a lot for you work!

Project Build gives SyntaxError: Unexpected token: punc ())

Hi,
I am using [email protected], ostrio:[email protected], ostrio:[email protected], aldeed:[email protected], aldeed:[email protected]. Browser chrome and macOS Sierra v 10.12.1.

My project is working fine but when I try to build it the following error occurs.

Errors prevented bundling:
While minifying app code:
packages/minifyStdJS_plugin.js:113:28: UglifyJS minification error:

SyntaxError: Unexpected token: punc ()) at packages/ostrio_autoform-files/lib/client/fileUpload.js line 16

within packages/ostrio_autoform-files.js (line: 195, col: 25, pos: 18455):

this.collectionName = () => {

at maybeThrowMinifyErrorBySourceFile (packages/minifyStdJS_plugin.js:113:28)
at packages/minifyStdJS_plugin.js:145:9
at Array.forEach (native)
at UglifyJSMinifier.processFilesForBundle (packages/minifyStdJS_plugin.js:130:9)

My relevant code is as follows:
images.js

this.Images = new FilesCollection({
  debug: true,
  collectionName: 'Images',
  allowClientCode: true, // Disallow remove files from Client,
  onbeforeunloadMessage: function () {
  return 'Upload is still in progress! Upload will be aborted if you leave this page!';
  },

  onBeforeUpload: function (file) {
    // Allow upload files under 10MB, and only in png/jpg/jpeg formats
    if (file.size <= 10485760 && /png|jpg|jpeg|mp4/i.test(file.ext)) {
      return true;
    } else {
      return 'Please upload image/video(png,jpg,jpeg,mp4 only), 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 Images.find().cursor;
  });
  Images.allow({
    insert: function() {
      return true;
    },
    update: function() {
      return true;
    },
    remove: function() {
      return true;
    }
  });
}

Sanitized error class

I'm using aldeed:autoform, ostrio:files and ostrio:autoform-files(as expected) to manage my forms.

While I worked just with the ostrio:files to upload images everything went fine, but when I put autoform-files on the scene I got this error after I've select the file:

Match error: Expected plain object

Image cannot be load when edit the colleciton

Story:

  • I have the Advertisements collection. There is a field called "AdvertiseImage" which using autoForm file to upload an image.

Issue:

  • It is working fine on insert new document.
  • On edit created document, the image show fileUpload box instead of uploaded image.

Investigation:

  • The id which giving to FileCollection.findOne({id}) is empty
  • On this break point
    ReactiveVar get empty
    image

only upload on submit

Is it possible to only upload the file when the user submit the autoform ? With the actual behavior an user can flood my server by sending a lot of fake files.
I have also another question about using afFieldInput to get the button to select the file. When I use it, I can choose my file but nothing happen when I submit my form (no error, just all the field are cleaned).

Issue when inserting a picture with autoform after modifying another parameter

Hello,

I am having an issue that I actually had for a while now with meteor-autoform-file, so it's not related to the most recent version or to Meteor 1.6 (had the same with 1.5).

Basically when I use autoform to edit a document with a file in it, if I first edit the file and then some other parameters (like String, Number, etc), it's all file. However, whenever I first edit another parameter and then a file, even if the file is correctly uploaded and displayed on the screen, it won't be saved.

Also, in both cases I see this in the console on the client:

Error: Unexpected object in htmljs in toText: [object Object] at HTMLVisitorSubtype.visitObject (htmljs.js?hash=1ac878018eee6c53ed1375dc7ee75fc6865666ae:292) at HTMLVisitorSubtype.visit (htmljs.js?hash=1ac878018eee6c53ed1375dc7ee75fc6865666ae:113) at Object.HTML.toText (htmljs.js?hash=1ac878018eee6c53ed1375dc7ee75fc6865666ae:668) at Object.Blaze._toText (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2468) at Blaze.View.updateAttributes (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1586) at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1934 at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744) at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1932 at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271) at viewAutorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1931)

Any idea what could be the issue?

No File upload button

Please forgive my newness to meteor, but I tried the example code and ran into an issue. The website starts up just fine and I see the title (with corresponding text box) and the Submit button. I also see the Picture text, but I cannot get the upload button (that goes along with it) to appear. I am using the very latest meteor 1.5.2 (with all of the required packages). I also installed meteortoys and I see that the "posts" and "Images" collections are created (but don't fill out since there isn't an upload button). Is there something else that needs done to get a visible "upload" button, or is something no longer working as intended? Thank you very much for any assistance.

FileId is not removed when removing file via the UI (click on remove)

the problem :

When removing the file via a click on 'Remove' and submitting the form, the target document still contains the id of the removed file.

my solution :

As a quick fix, I have overwritten the fileId helper as follows

Template.afFileUpload.helpers({
    [...]
    fileId() {
        return Template.instance().fileId.get() /* || this.value */; // <== commenting this part solves the issue
    },
    [...]
});

Getting an error with the published version

Exception in template helper: TypeError: Cannot read property 'find' of undefined
    at Object.uploadedFile (http://localhost:3000/packages/ostrio_autoform-files.js?hash=e71cbd4cce6282f7012a072add14293ffd54f877:138:60)
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2994:16
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1653:16
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:3046:66
    at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:3687:12)
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:3045:27
    at Object.Spacebars.dot (http://localhost:3000/packages/spacebars.js?hash=65db8b6a8e3fca189b416de702967b1cb83d57d5:234:13)
    at http://localhost:3000/packages/ostrio_autoform-files.js?hash=e71cbd4cce6282f7012a072add14293ffd54f877:72:65
    at .<anonymous> (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2677:44)
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1875:20

My code:

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

const Images = 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.ext)) {
      return true;
    }
    return 'Please upload image, with size equal or less than 10MB';
  },
});

export default Images;

and then in the schema

picture: {
  type: String,
  autoform: {
    afFieldInput: {
      type: 'fileUpload',
      collection: 'Images',
    },
  },
},

Setting default upload protocol?

Hello,

We noticed some issues when uploading big files with this package, and I know we fixed this in the past (before using autoform) by switching from DDP for upload to HTTP.

So I wondered what is the default protocol used by this package? Is it possible to change it somewhere? Thanks!

Exception in template helper

Hi,

I hope this is the right place for this and I'm sure the problem is with me and a mistake I've made or something I've misunderstood but I've been trying to figure it out for ages and I don't know what to try honestly.

After I upload a photo and submit the form I get the error message "Photo is required" even though there is a photo. I tried setting the field to optional: true and the form then submitted but I've no idea where the image went or how to find and use it.

Sorry, I'm sure this is a trivial problem and it's my lack of understanding but I really appreciate your help.

Thanks!

Only last file input works when using array of files.

I know it is a not very well supported feature, though the README.md is unclear whether what is unsupported is the array method or multi-file from a single <input>.

When using autoform's quickForm with a schema featuring an array of files, if you click the plus button multiple times to make the amount of file input fields you need before selecting any file, only the last of the fields will work.

Probably unrelated, but I couldn't do the schema exactly as described by the example on README.md:

// ...
  pictures: {
    type: [String],
    label: 'Choose file' # optional
  },
  "pictures.$": {
    autoform: {
      afFieldInput: {
// ...

It gave me an error:
Error: Invalid definition for pictures field: "type" may not be an array. Change it to Array.
So I had to change the schema definition as follow:

/* ... */
  pictures: {
    type: Array, // changed this
    label: 'Choose file' # optional
  },
  "pictures.$": {
    type: String,  // added this
    autoform: {
      afFieldInput: {
/* ... */

Error with version 2.1.2

Hello,

I am having an issue in my Meteor app since upgrading to 2.1.2. Whenever I open a page that subscribes to the Images collection, I have the error:

[meteor-autoform-files] No such collection "Images" [404]

Before that I had no issues at all. Could this be linked to the latest fix introduced in 2.1.2? Thanks!

arrow function doesn't get replaced with ecmascript

Running meteor with --production flag or deploying to Galaxy, one arrow function in fileUpload.js doesn't get replaced with ecmascript and es5-shim installed, and it breaks compatibility in Internet Explorer.
Every other code part works fine, this is the only arrow method that doesn't get replaced.

lib/client/fileUpload.js
starting with line 44
this.collectionName = () => { return this.data.atts.collection; };

rewrite fileUpload template

what should I do with template, for add to it some elemets (like Remove button available only for admin etc)? when I just copy it and rename it fires errors. What should I pass to it and how...
fileUpload.html

File remove only works on browser console

Clicking 'Remove' link on form only remove the record from collection, but not the file
But when I execute Images.remove({_id: 'RYQR6Zn3Mypgkpnkd'}) the file on upload folder removed
What did I do wrong?

Unexpected Token?

Here's a weird one for you, I'm getting an unexpected Token ' ) ' error on this line:

this.collectionName = () => this.data.atts.collection
It's more then likely something in my app ...but im not sure how to diaganose - any pointers?

simple example

this works
what are those lib/client files for ???
Posts = new Meteor.Collection('posts');
Schemas.Posts = new SimpleSchema({
title: {
type: String,
max: 60
},
picture: {
type: String,
autoform: {
afFieldInput: {
type: 'fileUpload',
collection: 'Images',
// uploadTemplate: 'uploadForm', // <- Optional
// previewTemplate: 'myFilePreview', // <- Optional
insertConfig: { // <- Optional, .insert() method options, see: https://github.com/VeliovGroup/Meteor-Files/wiki/Insert-(Upload)
meta: {},
isBase64: false,
transport: 'ddp',
streams: 'dynamic',
chunkSize: 'dynamic',
allowWebWorkers: true
}
}
}
}
});

TypeError: Cannot read property 'filesCollection' of undefined

I'm getting an error when I try to implement Ostrio-files, s3 and autoform directly with a QuickForm
I've done it on previous versions without hassle but on these:
ostrio:[email protected]
ostrio:[email protected]
ostrio:[email protected]
[email protected]
Using Mac
Also using dburles:mongo-collection-instances

Client logs

Exception from Tracker recompute function:
meteor.js?hash=c8108d734cc548d91539b054e14b613d0c4512cc:1010 TypeError: Cannot read property 'filesCollection' of undefined
    at Blaze.TemplateInstance.<anonymous> (fileUpload.js:26)
    at blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3398
    at Function.Template._withTemplateInstanceFunc (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3744)
    at fireCallbacks (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3394)
    at Blaze.View.<anonymous> (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3474)
    at fireCallbacks (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2014)
    at Object.Tracker.nonreactive (tracker.js:603)
    at blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2011
    at Object.Blaze._withCurrentView (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2271)
    at Object.Blaze._fireCallbacks (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2010)

Thanks in advance.

Issues with [email protected] (Version Constraint)

Hello @dr-dimitru , Thanks for this wonderful package.
I am working on an app using meteor 1.3.5.1 and ostrio:files works perfectly well but when add ostrio:autoform-files i get this error:

`Conflict: Constraint ostrio:[email protected] is not satisfied by ostrio:files 1.6.6.
 Constraints on package "ostrio:files":
 * ostrio:[email protected] <- ostrio:autoform-files 1.0.9`

What version of this package can I install to make it compatible with my current ostrio:files? Thanks

Uncaught TypeError: zeroBuffer.fill is not a function

Hello,

Thanks for the recent update of this package! However, when I try to use it in my app, I get the following error on the client and see the iron-router error page:

Uncaught TypeError: zeroBuffer.fill is not a function

The only way to get rid of this is to remove the package. I followed the example from the Readme, however I am using the S3 integration so I have my Files collection in the import folder and I import it using:

import Files from '../imports/api/files';

Could that be the source of the problem? Thanks!

Exception in template helper: idStringify after update to newest core package versions

I updated my meteor packages as shown below:

Changes to your project's package version selections from updating package versions:
                                              
accounts-base          upgraded from 1.3.1 to 1.3.2
babel-compiler         upgraded from 6.19.4 to 6.20.0
boilerplate-generator  upgraded from 1.1.1 to 1.2.0
ddp-client             upgraded from 2.0.0 to 2.1.0
ejson                  upgraded from 1.0.13 to 1.0.14
minifier-js            upgraded from 2.1.1 to 2.1.2
minimongo              upgraded from 1.2.1 to 1.3.0
modules                upgraded from 0.9.4 to 0.10.0
mongo                  upgraded from 1.1.22 to 1.2.0
mongo-dev-server       added, version 1.0.1
promise                upgraded from 0.8.9 to 0.9.0
webapp                 upgraded from 1.3.17 to 1.3.18

After restarting my application, I get the following error on the upload template:

Exception in template helper: idStringify@http://localhost:3000/packages/mongo-id.js?hash=345d169d517353f8146292b4abd24061721f8b26:104:20
get@http://localhost:3000/packages/id-map.js?hash=c7aea8dfa2bf46ff2ae0aa6c6cf09e36abc61d07:46:32
_getRawObjects@http://localhost:3000/packages/minimongo.js?hash=8cd7b53507123da052698c62ae61243696868347:1870:52
observeChanges@http://localhost:3000/packages/minimongo.js?hash=8cd7b53507123da052698c62ae61243696868347:1704:42
_depend@http://localhost:3000/packages/minimongo.js?hash=8cd7b53507123da052698c62ae61243696868347:1822:28
forEach@http://localhost:3000/packages/minimongo.js?hash=8cd7b53507123da052698c62ae61243696868347:1563:21
fetch@http://localhost:3000/packages/minimongo.js?hash=8cd7b53507123da052698c62ae61243696868347:1532:19
findOne@http://localhost:3000/packages/minimongo.js?hash=8cd7b53507123da052698c62ae61243696868347:2107:48
findOne@http://localhost:3000/packages/mongo.js?hash=191d09671a8d33340d4acaaa8c6015f73cc58072:404:36
findOne@http://localhost:3000/packages/ostrio_files.js?hash=da1f9645c3941d417a179125f36523e923269097:1301:34
uploadedFile@http://localhost:3000/packages/ostrio_autoform-files.js?hash=1f12457e52feebf281eef44e50074319fdd0740f:264:30

Which traces to the following code in the mondo-ids core package:

MongoID.idStringify = function (id) {                                                                 // 56
  if (id instanceof MongoID.ObjectID) {                                                               // 57
    return id.valueOf();                                                                              // 58
  } else if (typeof id === 'string') {                                                                // 59
    if (id === "") {                                                                                  // 60
      return id;                                                                                      // 61
    } else if (id.substr(0, 1) === "-" || // escape previously dashed strings                         // 62
               id.substr(0, 1) === "~" || // escape escaped numbers, true, false                      // 63
               MongoID._looksLikeObjectID(id) || // escape object-id-form strings                     // 64
               id.substr(0, 1) === '{') { // escape object-form strings, for maybe implementing later
      return "-" + id;                                                                                // 66
    } else {                                                                                          // 67
      return id; // other strings go through unchanged.                                               // 68
    }                                                                                                 // 69
  } else if (id === undefined) {                                                                      // 70
    return '-';                                                                                       // 71
  } else if (typeof id === 'object' && id !== null) {                                                 // 72
    throw new Error("Meteor does not currently support objects other than ObjectID as ids");          // 73
  } else { // Numbers, true, false, null                                                              // 74
    return "~" + JSON.stringify(id);                                                                  // 75
  }                                                                                                   // 76
};    

The error is thrown on line 72, ("Meteor does not currently support objects other than ObjectID as ids").

Reproduction of the error

I created for reproduction a new clean project with latest meteor version and core packages versions and added the following packages:

ostrio:[email protected]
ostrio:[email protected]
aldeed:collection2-core
dburles:[email protected]

plus

    "gridfs-stream": "^1.1.1",
    "simpl-schema": "^0.3.2"

Then I created the Images with GridFs integration, like from the wiki: https://github.com/VeliovGroup/Meteor-Files/wiki/GridFS-Integration

Then I created the Schema and the template, like in the README of this package, using a quickForm with type insert.

The error shows up.

My assumption is, that there is now a more sensitive id handling implemented in minimongo and I am not sure, whether there needs to be a change in this package or ostrio:files or if it is an error in the new minimongo version.

simple example

elementary example ? just cut and paste the provided code is not working.

Problem with GridFS

I use this in yogiben:admin with your sugegsted GridFS example code.

When I load an image in the edit document form it is displayed nicely.

But when I return to the same document the image is not displayed (however the String field is filled, so updating the image string seems to work).

Build error

When building for Linux with Meteor 1.4.0.1 or 1.4.1 the build fails.

Steps to reproduce:
meteor add ostrio:autoform-files
meteor build ../builtlnx --architecture os.linux.x86_64

Error message:
C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin.
minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier-
js\node_modules\uglify-js\lib\parse.js:196:18:
Unexpected token: punc ())
at new JS_Parse_Error
(C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin
.minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier
-js\node_modules\uglify-js\lib\parse.js:196:18)
at js_error
(C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin
.minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier
-js\node_modules\uglify-js\lib\parse.js:204:11)
at croak
(C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin
.minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier
-js\node_modules\uglify-js\lib\parse.js:675:9)
at token_error
(C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin
.minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier
-js\node_modules\uglify-js\lib\parse.js:683:9)
at unexpected
(C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin
.minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier
-js\node_modules\uglify-js\lib\parse.js:689:9)
at expr_atom
(C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin
.minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier
-js\node_modules\uglify-js\lib\parse.js:1184:13)
at maybe_unary
(C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin
.minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier
-js\node_modules\uglify-js\lib\parse.js:1358:19)
at expr_ops
(C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin
.minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier
-js\node_modules\uglify-js\lib\parse.js:1393:24)
at maybe_conditional
(C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin
.minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier
-js\node_modules\uglify-js\lib\parse.js:1398:20)
at maybe_assign
(C:\Users[...]\AppData\Local.meteor\packages\standard-minifier-js\1.1.8\plugin
.minifyStdJS.os\npm\node_modules\meteor\minifier-js\node_modules\meteor\minifier
-js\node_modules\uglify-js\lib\parse.js:1422:20)

Uncaught error when uploading an empty file

I'm having an issue:

  • If I upload an empty file, I encounter an uncaught error. Then, if I attempt to upload the same empty file again, the window becomes unresponsive, requiring a refresh to restore functionality.
  • I also noticed the same problem on the demo app located at https://files.veliov.com/.
  • Interestingly, I haven't observed this error when using the following code snippet:
SimpleSchema.setDefaultMessages({
  initialLanguage: 'en',
  messages: {
    en: {
     uploadError: (current) => i18n.__('SimpleSchema.uploadError', { label: current.label }), //File-upload
    },
  }
});
  • That's the error I had :

    {
    "isClientSafe": true,
    "error": 500,
    "reason": "[FilesCollection] [insert] Insert method accepts File, not a FileList. You need to provide a real File. File must have .name property, and its size must be larger than zero.",
    "message": "[FilesCollection] [insert] Insert method accepts File, not a FileList. You need to provide a real File. File must have .name property, and its size must be larger than zero. [500]",
    "errorType": "Meteor.Error"
    }

image

Notes:
I am using ostrio:[email protected] and ostrio:[email protected]

Then I upgraded those packages and the autoform package to latest versions and I have the same error with those verions :

Can´t find collection if not directly in global scope

I´ve encapsulated my collections in a Collections = {} object, but your lib is looking for it directly in the global scope.

var upload = global[template.collectionName()].insert({ ......

I actually don´t know if it´s possible in general to find a solution for it, but I thought I´ve mention it if others having the same problem.

As a workaround I´ve solved it by setting the collection to the global scope manually

import Collections from '/collections';

if (Meteor.isClient) {

    Template.your_template.onRendered(function () {
        global[Collections.YourImageCollection.collectionName] = Collections.YourImageCollection;
    })

}

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.