Skip to content

Commit

Permalink
Add Custom Parameter Example
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrieseberg committed Aug 21, 2015
1 parent a4bb96b commit a5706b6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
23 changes: 19 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 2,22 @@ module.exports = function (grunt) {

grunt.initConfig({
browserify: {
dev: {
src: 'example/example.js',
serve: {
src: 'example/example_default.js',
dest: 'example/bundle.js',
options: {
debug: true,
extensions: ['.js'],
transform: [
['reactify', {
'es6': true
}]
]
}
},

params: {
src: 'example/example_params.js',
dest: 'example/bundle.js',
options: {
debug: true,
Expand All @@ -22,7 36,7 @@ module.exports = function (grunt) {
port: 8000,
background: false,
},
test: {
serve: {
options: {
script: 'server.js'
}
Expand All @@ -33,5 47,6 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-express-server');

grunt.registerTask('default', ['browserify:dev', 'express:test']);
grunt.registerTask('default', ['browserify:serve', 'express:serve']);
grunt.registerTask('params', ['browserify:params', 'express:serve']);
};
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 155,24 @@ var djsConfig = {
}
```

### Add Custom Parameters
To add custom parameters to your request, add a `params` property to your Dropzone.js configuration object. You can check out the included example by running `grunt params`.

```
var djsConfig = {
addRemoveLinks: true,
params: {
myParameter: "I'm a parameter!"
}
};
var componentConfig = {
postUrl: '/uploadHandler'
};
React.render(<DropzoneComponent config={componentConfig} djsConfig={djsConfig} />, document.getElementById('content'));
```

## Server Example
This component comes with a small server example. To try it out, simply run `npm install` and then `grunt` from the component's folder. Visit `http://localhost:8000/example/` to see the uploads working.

Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions example/example_params.js
Original file line number Diff line number Diff line change
@@ -0,0 1,21 @@
'use strict';

var React = require('../node_modules/react');
var DropzoneComponent = require('../lib/dropzone.js');

// Add params to your dropzonejs configuration object, like so:
var djsConfig = {
addRemoveLinks: true,
params: {
myParam: 'Hello from a parameter!',
anotherParam: 43
}
};

var componentConfig = {
showFiletypeIcon: false,
postUrl: '/uploadHandler'
};

// Render
React.render(<DropzoneComponent config={componentConfig} djsConfig={djsConfig} />, document.getElementById('content'));
9 changes: 8 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 6,23 @@ var express = require('express'),
app = module.exports = express();
app.set('port', process.env.PORT || 3000);


app.use(express.static('./'));
// Dest is not necessary if you are happy with the default: /tmp
// app.use(multer({ dest: 'uploads' }));
app.use(new MulterImpl({}).init());

app.post('/uploadHandler', function (req, res) {
// This block is only relevant to users
// interested in custom parameters - you
// can delete/ignore it as you wish
if (req.body) {
console.dir(req.body);
}

res.sendStatus(200);
});

module.exports = app.listen(app.get('port'), function() {
console.log('Express server listening on port ' app.get('port'));
console.log('Visit http://localhost:8000/example/ to check out the upload example');
});

0 comments on commit a5706b6

Please sign in to comment.