Stefan B.
Stefan B.

Reputation: 384

Node js download folder via HTTP

I have a litle problem to download a folder in node js. My problem is that I request, via http, a whole folder and I get a stream back but this stream contains the folder and the files. All solutions I found (like fs.createWriteStream) only work with simple files not an whole file structure.

The following example request I have:

curl -X POST -H "content-type:application/json" -d '{"swaggerUrl":"http://petstore.swagger.io/v2/swagger.json"}' http://generator.swagger.io/api/gen/servers/nodejs

This request get a JSON back with a download link (like: http://generator.swagger.io:80/api/gen/download/1445674072116)

If I click on the link, no problem the download start immediately and the download contains a folder and a file.

But if I try this:

    let path = __dirname + '/../api/clients/typescript/';
    request(body.link).pipe(fs.createWriteStream(path))

I get the following error:

Error: EISDIR: illegal operation on a directory, open 

I guess I make something wrong. Know anybody a solution or have a little hint to download a whole file structure via http and save this structure to the local file system ?

Thnaks :)

Upvotes: 1

Views: 2013

Answers (1)

Stefan B.
Stefan B.

Reputation: 384

Okay my fault. I opened this link via safari and safari auto unzip the file.

Upvotes: 1

Related Questions