Skip to content

Commit

Permalink
Merge branch 'node-formidablegh-88-plattform-independent-upload-dir'
Browse files Browse the repository at this point in the history
* node-formidablegh-88-plattform-independent-upload-dir:
  Document new uploadDir detection
  Plattform independent upload dir detection

Fixes node-formidable#88
  • Loading branch information
felixge committed Sep 15, 2011
2 parents 3559b0c + d6b7def commit 0e5ae7c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ Creates a new incoming form.

The encoding to use for incoming form fields.

#### incomingForm.uploadDir = '/tmp'
#### incomingForm.uploadDir = process.env.TMP || '/tmp' || process.cwd()

The directory for placing file uploads in. You can later on move them using `fs.rename()`.
The directory for placing file uploads in. You can later on move them using
`fs.rename()`. The default directoy is picked at module load time depending on
the first existing directory from those listed above.

#### incomingForm.keepExtensions = false

Expand Down
17 changes: 16 additions & 1 deletion lib/incoming_form.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if (global.GENTLY) require = GENTLY.hijack(require);

var fs = require('fs');
var util = require('./util'),
path = require('path'),
File = require('./file'),
Expand All @@ -17,7 +18,7 @@ function IncomingForm() {

this.maxFieldsSize = 2 * 1024 * 1024;
this.keepExtensions = false;
this.uploadDir = '/tmp';
this.uploadDir = IncomingForm.UPLOAD_DIR;
this.encoding = 'utf-8';
this.headers = null;
this.type = null;
Expand All @@ -32,6 +33,20 @@ function IncomingForm() {
util.inherits(IncomingForm, EventEmitter);
exports.IncomingForm = IncomingForm;

IncomingForm.UPLOAD_DIR = (function() {
var dirs = [process.env.TMP, '/tmp', process.cwd()];
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var isDirectory = false;

try {
isDirectory = fs.statSync(dir).isDirectory();
} catch (e) {}

if (isDirectory) return dir;
}
})();

IncomingForm.prototype.parse = function(req, cb) {
this.pause = function() {
try {
Expand Down

0 comments on commit 0e5ae7c

Please sign in to comment.