Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2do2go/iframe-file-upload-middleware
Ajax file uploading iframe fallback for expressjs
https://github.com/2do2go/iframe-file-upload-middleware
Last synced: 29 days ago
JSON representation
Ajax file uploading iframe fallback for expressjs
- Host: GitHub
- URL: https://github.com/2do2go/iframe-file-upload-middleware
- Owner: 2do2go
- Created: 2013-03-29T13:56:15.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-10-07T06:29:39.000Z (over 10 years ago)
- Last Synced: 2024-11-18T19:02:51.054Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 167 KB
- Stars: 4
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ajax file uploading iframe fallback for expressjs
express framework already provides convenient way for uploading files using
bodyParser. Ajax file uploading works great at modern browsers but we
need a fallback for some "explorers" (yes, i'm watching at you msie) that
doesn't support ajax file uploading. Fallback in this case - loading file using
iframe. This lightweight (about 50 lines of code without dependencies)
middleware provides iframe file uploading support for server side.## Usage
server setup, at your app.js
```js
var app = express.createServer();
app.use(express.bodyParser());var iframeFileUpload = require('iframe-file-upload-middleware');
iframeFileUpload.addRedirectResponder(app);
app.post(/^.*\/upload$/, iframeFileUpload.middleware());
```now you can bind your handler at some upload url e.g. '/images/upload' and
process uploads as you usually do, e.g.```js
app.post('/images/upload', function(req, res) {
res.json({filename: path.filename(req.files.image.path)});
});
```
client setup using [jquery file upload](http://blueimp.github.com/jQuery-File-Upload/)```js
$('input[name=image]').fileupload({
url: '/images/upload',
redirect: 'default',
dataType: 'json'
}).on('fileuploaddone', function(event, data) {
alert(data.result.filename);
});
```now you can upload image using file input and recives it's file name to the
client. It will work in browsers (using ajax file upload) and in explorer
using (iframe file uploading).