0

I have asked various questions and got only limited answers and it has gotten me this far: Mongoose code :

app.get('/Download/:file(*)', function (req, res) {
    grid.mongo = mongoose.mongo;
    var gfs = grid(conn.db);
    var file = req.params.file
    var fs_write_stream = fs.createWriteStream('Program.cs');
    
    var readstream = gfs.createReadStream({ filename: file });
    
    readstream.pipe(fs_write_stream);

    res.download(__dirname+'/Program.cs', 'Solution.cs', function (err) {
        if (err) throw err;
        else console.log("check console");
    });
})

Angular code:

$scope.Download = function () {
        $http.get(url + "/Download/"+"Program.cs")
        .success(function (res) {
            console.log(res);
        })}

When I open my console angular just returns a blank line, when i look into the network aspect the header sais this:


Response Header

I want to be able to store this file to my local file system to a path that I want to be able to choose myself. PLEASE help me out, I'm desperate, I have looked EVERYwhere for a solution, thank you very much in advance!

Community
  • 1
  • 1
Tom Kustermans
  • 521
  • 2
  • 8
  • 31
  • Are you talking about the local filesystem on the *server* or on the *client*? (the latter should be impossible because a website can not tell the web browser where to save a file) – Philipp Jan 06 '16 at 13:55
  • I just want the client to be able to download a file that is stored in my mongodb, like any other site that allows you to download a file like a .pdf or .txt – Tom Kustermans Jan 06 '16 at 14:00

1 Answers1

0

Try this instead of your client side download attempt:

<a class="btn" href="/Download/Program.cs" download>
Yerken
  • 1,944
  • 1
  • 14
  • 18
  • gave this error for me: "HTTP Error 404.7 - Not Found The request filtering module is configured to deny the file extension." this probably because it's a '.cs' file .. but that's how I want to download it. this because it's the point of my website. the teachers are supposed to download these '.cs' files so they can run the code and correct where nessecary – Tom Kustermans Jan 06 '16 at 14:14
  • you need to configure your serving server. http://stackoverflow.com/questions/13455939/http-error-404-7-not-found-the-request-filtering-module-is-configured-to-deny – Yerken Jan 06 '16 at 14:18
  • I got that working, I think.. now it's just telling me "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." don't know what he's talking about – Tom Kustermans Jan 06 '16 at 14:52
  • Also it shows : "Physical Path "path to application file"\Download\Program.cs " but this "\Download" file doesn't exist so ofcourse it's not going to find anything there. what's going on ? – Tom Kustermans Jan 06 '16 at 14:53
  • I just created this filepath myself to see what outcome it would give me, and it gave this "The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map." how do I solve this ? and also, I do I change the directory where it reads from ? – Tom Kustermans Jan 06 '16 at 15:02
  • your nodejs is running behind IIS? – Yerken Jan 06 '16 at 15:51
  • I truly have no idea how to check that. – Tom Kustermans Jan 06 '16 at 15:53