Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP PUT Request with Node.js

Tags:

node.js

I'm trying to figure out how to make an HTTP PUT request with node.js. I've tried a lot of different things, but can't get it working.

The idea is to have a method for putting the file, eg:

function putFile(file_path, callback) {
    // Put the file
}

Any help would be appreciated.

like image 922
mellowsoon Avatar asked Aug 29 '11 00:08

mellowsoon


1 Answers

Here is an example which sends a POST request: http://nodejs.org/docs/v0.4.11/api/http.html#http.request , basically you just have to change it to PUT.

You could open your file using createReadStream() and pipe() it to the response object.

Here is another example which uses readFile(), the problem with that is that the whole file is loaded into memory, so better use createReadStream() and pipe() if the files are large.

like image 184
stewe Avatar answered Oct 05 '22 02:10

stewe