Comparing version 0.1.0 to 0.1.1
@@ -56,3 +56,3 @@ var fs = require('fs'), | ||
writeFile(directory + "/" + name + ".bin", new Buffer(0)), | ||
writeFile(directory + "/" + name + ".info", JSON.stringify({entityLength: entityLength, offset: 0, meta: meta}), "utf8"), | ||
writeFile(directory + "/" + name + ".info", JSON.stringify({name: name, entityLength: entityLength, offset: 0, meta: meta}), "utf8"), | ||
function() { | ||
@@ -78,2 +78,6 @@ return name; | ||
if (options.maxFileSize != null && isNaN(options.maxFileSize)) { | ||
throw new Error("maxFileSize option must be a number"); | ||
} | ||
function getInfo(id) { | ||
@@ -85,3 +89,7 @@ return readFile(options.directory + "/" + id + ".info").then(JSON.parse); | ||
getPositiveIntHeader(req, "Entity-Length").then(function(entityLength) { | ||
return createEmptyFile(crypto.randomBytes(16).toString('hex'), options.directory, entityLength, {}); | ||
if (options.maxFileSize != null && entityLength > options.maxFileSize) { | ||
throw new BadRequest("File exceeds maximum allowed file size of " + options.maxFileSize + " bytes"); | ||
} | ||
return createEmptyFile(crypto.randomBytes(16).toString('hex'), options.directory, entityLength, {contentType: req.get('Content-Type') || null, filename: req.get('Entity-Name') || null}); | ||
}).then(function(name) { | ||
@@ -145,3 +153,7 @@ res.set('Location', url.resolve(req.protocol + '://' + req.get('host') + req.originalUrl + "/", name)); | ||
info.offset = byteOffset; | ||
return writeFile(options.directory + "/" + id + ".info", JSON.stringify(info), "utf8"); | ||
var promise = writeFile(options.directory + "/" + id + ".info", JSON.stringify(info), "utf8"); | ||
if (typeof options.complete === "function") { | ||
options.complete(info); | ||
} | ||
return promise; | ||
} | ||
@@ -148,0 +160,0 @@ return Promise.resolve(); |
{ | ||
"name": "tus", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Node.js resumable upload middleware for express/connect", | ||
@@ -5,0 +5,0 @@ "main": "lib/tus.js", |
@@ -13,2 +13,30 @@ # node-tus | ||
## Usage | ||
To attach the resumable upload middleware to express or connect, create an upload server by calling `createServer` passing it an `options` object. Available options are: | ||
- **directory** - String - Path where to upload the files (required) | ||
- **maxFileSize** - Number - Maximum file size for uploads, in bytes (optional) | ||
- **complete** - Function - Callback to inform when a file (all chunks) have been uploaded. Passes the file metadata as an argument (optional) | ||
Example: | ||
```js | ||
var express = require("express"), | ||
upload = require("tus"); | ||
var app = express(); | ||
var port = 3000; | ||
app.use("/files", upload.createServer({ | ||
directory: __dirname + "/uploads", | ||
maxFileSize: 1024, | ||
complete: function(fileMetadata) { | ||
console.log("File uploaded with the following metadata:", fileMetadata); | ||
} | ||
})); | ||
app.listen(port); | ||
``` | ||
## Running Tests | ||
@@ -15,0 +43,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56426
185
48