Skip to content

Commit f4be9c7

Browse files
committed
v2.0.4
- Dependencies update - Compatibility with `meteor@1.5.2.2` - Implement #30 , thanks to @marcoschwartz - Added: `insertConfig` in a Schema for passing [`.insert()` method option](https://github.com/VeliovGroup/Meteor-Files/wiki/Insert-(Upload) ) - Added: support for attributes in `afQuickField` for passing [`.insert()` method option](https://github.com/VeliovGroup/Meteor-Files/wiki/Insert-(Upload) ) - Minor codebase enhancements
1 parent 59d8566 commit f4be9c7

File tree

4 files changed

+67
-27
lines changed

4 files changed

+67
-27
lines changed

.versions

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
aldeed:autoform@6.2.0
2-
allow-deny@1.0.6
2+
allow-deny@1.0.9
33
babel-compiler@6.20.0
44
babel-runtime@1.0.1
55
base64@1.0.10
@@ -11,14 +11,13 @@ caching-compiler@1.1.9
1111
caching-html-compiler@1.0.6
1212
callback-hook@1.0.10
1313
check@1.2.5
14-
coffeescript@1.11.1_3
15-
ddp@1.3.0
16-
ddp-client@2.1.0
14+
ddp@1.3.1
15+
ddp-client@2.1.3
1716
ddp-common@1.2.9
18-
ddp-server@2.0.0
17+
ddp-server@2.0.2
1918
deps@1.0.12
2019
diff-sequence@1.0.7
21-
ecmascript@0.8.2
20+
ecmascript@0.8.3
2221
ecmascript-runtime@0.4.1
2322
ecmascript-runtime-client@0.4.3
2423
ecmascript-runtime-server@0.4.1
@@ -31,20 +30,20 @@ id-map@1.0.9
3130
jquery@1.11.10
3231
livedata@1.0.18
3332
logging@1.1.17
34-
meteor@1.7.1
35-
minimongo@1.3.0
33+
meteor@1.7.2
34+
minimongo@1.3.2
3635
modules@0.10.0
3736
modules-runtime@0.8.0
3837
momentjs:moment@2.10.6
39-
mongo@1.2.0
38+
mongo@1.2.2
4039
mongo-dev-server@1.0.1
4140
mongo-id@1.0.6
4241
npm-mongo@2.2.30
4342
observe-sequence@1.0.16
4443
ordered-dict@1.0.9
45-
ostrio:autoform-files@2.0.3
46-
ostrio:cookies@2.2.2
47-
ostrio:files@1.8.3
44+
ostrio:autoform-files@2.0.4
45+
ostrio:cookies@2.2.3
46+
ostrio:files@1.9.0
4847
promise@0.9.0
4948
random@1.0.10
5049
reactive-dict@1.1.9
@@ -59,5 +58,5 @@ tracker@1.1.3
5958
ui@1.0.13
6059
underscore@1.0.10
6160
url@1.1.0
62-
webapp@1.3.18
61+
webapp@1.3.19
6362
webapp-hashing@1.0.9

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ Schemas.Posts = new SimpleSchema({
6868
type: 'fileUpload',
6969
collection: 'Images',
7070
uploadTemplate: 'uploadField', // <- Optional
71-
previewTemplate: 'uploadPreview' // <- Optional
71+
previewTemplate: 'uploadPreview', // <- Optional
72+
insertConfig: { // <- Optional, .insert() method options, see: https://github.com/VeliovGroup/Meteor-Files/wiki/Insert-(Upload)
73+
meta: {},
74+
isBase64: false,
75+
transport: 'ddp',
76+
streams: 'dynamic',
77+
chunkSize: 'dynamic',
78+
allowWebWorkers: true
79+
}
7280
}
7381
}
7482
}
@@ -91,6 +99,14 @@ Generate the form with `{{> quickform}}` or `{{#autoform}}` e.g.:
9199
{{> afQuickField name="picture"}}
92100
<button type="submit" class="btn btn-primary">Insert</button>
93101
{{/autoForm}}
102+
103+
<!-- OR with .insert() method options -->
104+
<!-- See: https://github.com/VeliovGroup/Meteor-Files/wiki/Insert-(Upload) -->
105+
{{#autoForm id="postsInsertForm" collection="Posts" type="insert"}}
106+
{{> afQuickField name="title"}}
107+
{{> afQuickField name="picture" transport="http" allowWebWorkers="false"}}
108+
<button type="submit" class="btn btn-primary">Insert</button>
109+
{{/autoForm}}
94110
```
95111

96112
##### Update mode:
@@ -181,3 +197,9 @@ picture: {
181197
<a href="{{file.link}}">{{file.original.name}}</a>
182198
</template>
183199
```
200+
201+
Support this project:
202+
======
203+
This project wouldn't be possible without [ostr.io](https://ostr.io).
204+
205+
Using [ostr.io](https://ostr.io) you are not only [protecting domain names](https://ostr.io/info/domain-names-protection), [monitoring websites and servers](https://ostr.io/info/monitoring), using [Prerendering for better SEO](https://ostr.io/info/prerendering) of your JavaScript website, but support our Open Source activity, and great packages like this one could be available for free.

lib/client/fileUpload.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
import { _ } from 'meteor/underscore';
12
import { Meteor } from 'meteor/meteor';
23
import { AutoForm } from 'meteor/aldeed:autoform';
34
import { Template } from 'meteor/templating';
45
import { ReactiveVar } from 'meteor/reactive-var';
56
import { Mongo } from 'meteor/mongo';
67

8+
const defaultInsertOpts = {
9+
meta: {},
10+
isBase64: false,
11+
transport: 'ddp',
12+
streams: 'dynamic',
13+
chunkSize: 'dynamic',
14+
allowWebWorkers: true
15+
};
16+
717
Template.afFileUpload.onCreated(function () {
818
if (!this.data) {
919
this.data = {
@@ -16,6 +26,16 @@ Template.afFileUpload.onCreated(function () {
1626
: (global[this.data.atts.collection] || Meteor.connection._mongo_livedata_collections[this.data.atts.collection].filesCollection);
1727
this.uploadTemplate = this.data.atts.uploadTemplate || null;
1828
this.previewTemplate = this.data.atts.previewTemplate || null;
29+
this.insertConfig = Object.assign({}, this.data.atts.insertConfig || {});
30+
delete this.data.atts.insertConfig;
31+
this.insertConfig = Object.assign(this.insertConfig, _.pick(this.data.atts, Object.keys(defaultInsertOpts)));
32+
33+
if (!isNaN(this.insertConfig.streams) || this.insertConfig.streams !== 'dynamic') {
34+
this.insertConfig.streams = parseInt(this.insertConfig.streams);
35+
}
36+
if (!isNaN(this.insertConfig.chunkSize) || this.insertConfig.chunkSize !== 'dynamic') {
37+
this.insertConfig.chunkSize = parseInt(this.insertConfig.chunkSize);
38+
}
1939

2040
if (!this.collection) {
2141
throw new Meteor.Error(404, '[meteor-autoform-files] No such collection "' + this.data.atts.collection + '"');
@@ -25,10 +45,10 @@ Template.afFileUpload.onCreated(function () {
2545
return this.data.atts.collection;
2646
};
2747

28-
this.currentUpload = new ReactiveVar(false);
29-
this.inputName = this.data.name;
30-
this.fileId = new ReactiveVar(this.data.value || false);
31-
this.formId = this.data.atts.id;
48+
this.currentUpload = new ReactiveVar(false);
49+
this.inputName = this.data.name;
50+
this.fileId = new ReactiveVar(this.data.value || false);
51+
this.formId = this.data.atts.id;
3252
return;
3353
});
3454

@@ -51,7 +71,7 @@ Template.afFileUpload.helpers({
5171
if (typeof _id !== 'string' || _id.length === 0) {
5272
return null;
5373
}
54-
return template.collection.findOne({_id:_id});
74+
return template.collection.findOne({_id});
5575
}
5676
});
5777

@@ -73,13 +93,12 @@ Template.afFileUpload.events({
7393
},
7494
'change [data-files-collection-upload]'(e, template) {
7595
if (e.currentTarget.files && e.currentTarget.files[0]) {
76-
const upload = template.collection.insert({
77-
file: e.currentTarget.files[0],
78-
streams: 'dynamic',
79-
chunkSize: 'dynamic'
80-
}, false);
96+
const opts = Object.assign({}, defaultInsertOpts, template.insertConfig, {
97+
file: e.currentTarget.files[0]
98+
});
8199

82-
const ctx = AutoForm.getValidationContext(template.formId);
100+
const upload = template.collection.insert(opts, false);
101+
const ctx = AutoForm.getValidationContext(template.formId);
83102

84103
upload.on('start', function () {
85104
ctx.reset();

package.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package.describe({
22
name: 'ostrio:autoform-files',
33
summary: 'File upload for AutoForm using ostrio:files',
44
description: 'File upload for AutoForm using ostrio:files',
5-
version: '2.0.3',
5+
version: '2.0.4',
66
git: 'https://github.com/VeliovGroup/meteor-autoform-file.git'
77
});
88

@@ -17,7 +17,7 @@ Package.onUse(function(api) {
1717
'reactive-var',
1818
'templating',
1919
'aldeed:autoform@6.2.0',
20-
'ostrio:files@1.8.3'
20+
'ostrio:files@1.9.0'
2121
]);
2222

2323
api.addFiles([

0 commit comments

Comments
 (0)