Skip to content

Commit 15c91e8

Browse files
committed
updated README on upload template configs
1 parent 8b46263 commit 15c91e8

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,35 @@ Generate the form with `{{> quickform}}` or `{{#autoform}}` e.g.:
127127

128128
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).
129129

130+
### Accept configuration
131+
132+
##### Usage
133+
134+
You can configure the file selector, to only allow certain types of files using the `accept` property:
135+
136+
```javascript
137+
Schemas.Posts = new SimpleSchema({
138+
title: {
139+
type: String,
140+
max: 60
141+
},
142+
picture: {
143+
type: String,
144+
autoform: {
145+
afFieldInput: {
146+
type: 'fileUpload',
147+
collection: 'Images',
148+
accept: 'image/*' // or use explicit ext names like .png,.jpg
149+
}
150+
}
151+
}
152+
});
153+
```
154+
155+
The accept values works makes use of the native HTML `accept` attribute. Read more at the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers).
156+
157+
Please read the section on **custom upload templates** and how to integrate configs like *accept* to your custom template.
158+
130159
### Multiple images // not fully supported yet
131160
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)
132161

@@ -171,13 +200,21 @@ picture: {
171200
}
172201
```
173202

203+
```html
204+
<template name="myFileUpload">
205+
<a href="{{file.link}}">{{file.original.name}}</a>
206+
</template>
207+
```
208+
209+
174210
### Custom upload template
175211

176212
Your custom file upload template data context will be:
177213

178214
- *file* - FS.File instance
179215
- *progress*
180216
- *status*
217+
- *config* an object containing several configs to upload behavior, such as `accept`
181218
- Other fields from [`FileUpload` instance](https://github.com/VeliovGroup/Meteor-Files/wiki/Insert-(Upload)#fileupload-methods-and-properties)
182219

183220
```javascript
@@ -194,11 +231,28 @@ picture: {
194231
```
195232

196233
```html
197-
<template name="myFilePreview">
198-
<a href="{{file.link}}">{{file.original.name}}</a>
234+
<template name="myFileUpload">
235+
{{#with progress}}
236+
<!-- if there is a progress present, we can use it to determine the upload progress -->
237+
<progress value="{{this.get}}" max="100"></progress>
238+
{{/with}}
239+
{{#with file}}
240+
<!-- if there is a file present, we have a file selected for upload -->
241+
<span>Uploading {{this.name}}</span>
242+
{{else}}
243+
<!-- otherwise we provide the upload -->
244+
<input data-files-collection-upload class="form-control af-file-upload-capture" type="file" accept="{{config.accept}}" />
245+
{{/if}}
199246
</template>
200247
```
201248

249+
##### Note on upload configs:
250+
251+
If you pass any config, like `accept` your upload data won't be falsey anymore,
252+
so you should update your template to the example above and check for each of the given properties.
253+
This is however backwards-compatible and will not break your older templates if you don't need any of the upload config
254+
introduced in > 2.1.4 releases.
255+
202256
Support this project:
203257
======
204258
This project wouldn't be possible without [ostr.io](https://ostr.io).

0 commit comments

Comments
 (0)