🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

iframe-file-upload-middleware

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iframe-file-upload-middleware

Ajax file uploading iframe fallback for expressjs

Source
npmnpm
Version
0.1.2
Version published
Weekly downloads
2
-60%
Maintainers
1
Weekly downloads
 
Created
Source

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

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.

app.post('/images/upload', function(req, res) {
	res.json({filename: path.filename(req.files.image.path)});
});

client setup using jquery file upload

$('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).

Keywords

express

FAQs

Package last updated on 01 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts