You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Upload and manage files with autoForm via [`ostrio:files`](https://github.com/VeliovGroup/Meteor-Files). This package was ported from `yogiben:autoform-file` to use with [`ostrio:files`](https://github.com/VeliovGroup/Meteor-Files) instead of the already deprecated CollectionFS.
6
14
7
-
###Quick Start:
15
+
## Quick Start:
8
16
9
-
- Install `meteor add ostrio:autoform-files`
10
-
- Install `meteor add ostrio:files`, *if not yet installed*
11
-
- Add this config to `simpl-schema` NPM package (depending of the language that you are using):
12
-
```javascript
17
+
1. Install `meteor add ostrio:autoform-files`
18
+
2. Install `meteor add ostrio:files`, *if not yet installed*
19
+
3. Add this config to `simpl-schema` NPM package (depending of the language that you are using):
allowClientCode:true, // Required to let you remove uploaded file
27
41
onBeforeUpload(file) {
28
42
// Allow upload files under 10MB, and only in png/jpg/jpeg formats
29
43
if (file.size<=10485760&&/png|jpg|jpeg/i.test(file.ext)) {
30
44
returntrue;
31
-
} else {
32
-
return'Please upload image, with size equal or less than 10MB';
33
45
}
46
+
return'Please upload image, with size equal or less than 10MB';
34
47
}
35
48
});
36
49
@@ -44,16 +57,18 @@ if (Meteor.isServer) {
44
57
});
45
58
}
46
59
```
60
+
47
61
__Note:__ If you don't use Mongo Collection instances (`dburles:mongo-collection-instances`), then the `Images` 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.
48
62
49
63
To start using `dburles:mongo-collection-instances` simply install it:
64
+
50
65
```shell
51
66
meteor add dburles:mongo-collection-instances
52
67
```
53
68
69
+
5. Define your schema and set the `autoform` property like in the example below
54
70
55
-
- Define your schema and set the `autoform` property like in the example below
56
-
```javascript
71
+
```js
57
72
Schemas = {};
58
73
Posts =newMeteor.Collection('posts');
59
74
Schemas.Posts=newSimpleSchema({
@@ -89,9 +104,9 @@ The `collection` property must be the same as name of your *FilesCollection* (*c
89
104
90
105
Generate the form with `{{> quickform}}` or `{{#autoform}}` e.g.:
@@ -127,13 +142,13 @@ Generate the form with `{{> quickform}}` or `{{#autoform}}` e.g.:
127
142
128
143
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](https://github.com/VeliovGroup/meteor-autoform-file/issues/9).
129
144
130
-
###Accept configuration
145
+
## Accept configuration
131
146
132
-
#####Usage
147
+
### Usage
133
148
134
149
You can configure the file selector, to only allow certain types of files using the `accept` property:
135
150
136
-
```javascript
151
+
```js
137
152
Schemas.Posts=newSimpleSchema({
138
153
title: {
139
154
type:String,
@@ -156,10 +171,13 @@ The accept values works makes use of the native HTML `accept` attribute. Read mo
156
171
157
172
Please read the section on **custom upload templates** and how to integrate configs like *accept* to your custom template.
158
173
159
-
### Multiple images // not fully supported yet
174
+
## Multiple images
175
+
176
+
Multiple images — __not fully supported yet__
177
+
160
178
If you want to use an array of images inside you have to define the autoform on on the [schema key](https://github.com/aldeed/meteor-simple-schema#schema-keys)
161
179
162
-
```javascript
180
+
```js
163
181
Schemas.Posts=newSimpleSchema({
164
182
title: {
165
183
type:String,
@@ -169,7 +187,7 @@ Schemas.Posts = new SimpleSchema({
169
187
type:Array,
170
188
label:'Choose file'// <- Optional
171
189
},
172
-
"pictures.$": {
190
+
'pictures.$': {
173
191
type:String,
174
192
autoform: {
175
193
afFieldInput: {
@@ -178,36 +196,37 @@ Schemas.Posts = new SimpleSchema({
178
196
}
179
197
}
180
198
}
181
-
})
199
+
});
182
200
```
183
201
184
-
###Custom file preview
202
+
## Custom file preview
185
203
186
204
Your custom file preview template data context will be:
Your custom file upload template data context will be:
213
232
@@ -217,20 +236,22 @@ Your custom file upload template data context will be:
217
236
-*config* an object containing several configs to upload behavior, such as `accept`
218
237
- Other fields from [`FileUpload` instance](https://github.com/VeliovGroup/Meteor-Files/wiki/Insert-(Upload)#fileupload-methods-and-properties)
219
238
220
-
```javascript
221
-
picture: {
222
-
type:String,
223
-
autoform: {
224
-
afFieldInput: {
225
-
type:'fileUpload',
226
-
collection:'Images',
227
-
uploadTemplate:'myFileUpload'
239
+
```js
240
+
({
241
+
picture: {
242
+
type:String,
243
+
autoform: {
244
+
afFieldInput: {
245
+
type:'fileUpload',
246
+
collection:'Images',
247
+
uploadTemplate:'myFileUpload'
248
+
}
228
249
}
229
250
}
230
-
}
251
+
});
231
252
```
232
253
233
-
```html
254
+
```handlebars
234
255
<template name="myFileUpload">
235
256
{{#with progress}}
236
257
<!-- if there is a progress present, we can use it to determine the upload progress -->
@@ -246,15 +267,14 @@ picture: {
246
267
</template>
247
268
```
248
269
249
-
#####Note on upload configs:
270
+
### Note on upload configs:
250
271
251
272
If you pass any config, like `accept` your upload data won't be falsey anymore,
252
273
so you should update your template to the example above and check for each of the given properties.
253
274
This is however backwards-compatible and will not break your older templates if you don't need any of the upload config
254
275
introduced in > 2.1.4 releases.
255
276
256
-
Support this project:
257
-
======
258
-
This project wouldn't be possible without [ostr.io](https://ostr.io).
277
+
## Support this project:
259
278
260
-
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.
279
+
-[Become a patron](https://www.patreon.com/bePatron?u=20396046) — support my open source contributions with monthly donation
280
+
- Use [ostr.io](https://ostr.io) — [Monitoring](https://snmp-monitoring.com), [Analytics](https://ostr.io/info/web-analytics), [WebSec](https://domain-protection.info), [Web-CRON](https://web-cron.info) and [Pre-rendering](https://prerendering.com) for a website
0 commit comments