mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
Add support for writing binary files to a web server.
This works in current Chromium and Firefox 3.6. It does not work in Opera 10.
This commit is contained in:
+18
-1
@@ -9,7 +9,24 @@ var sys = require("sys"),
|
||||
http.createServer(function (request, response) {
|
||||
var uri = url.parse(request.url).pathname,
|
||||
filename = path.join(process.cwd(), uri);
|
||||
console.log(url + " " + uri + " " + filename);
|
||||
console.log(request.method + " " + url + " " + uri + " " + filename);
|
||||
function put() {
|
||||
var alldata = "";
|
||||
request.on("data", function (data) {
|
||||
alldata += data;
|
||||
});
|
||||
request.on("end", function () {
|
||||
fs.writeFile(filename, alldata, "binary", function (err) {
|
||||
// todo: add error handling
|
||||
response.writeHead(200);
|
||||
response.end();
|
||||
});
|
||||
});
|
||||
}
|
||||
if (request.method === "PUT") {
|
||||
put(request, response);
|
||||
return;
|
||||
}
|
||||
fs.stat(filename, function (err, stats) {
|
||||
if (!err && stats.isFile()) {
|
||||
fs.readFile(filename, "binary", function (err, file) {
|
||||
|
||||
Reference in New Issue
Block a user