0

Im a mobile app developer and new to web apps. Im trying to implement upload and download a file in the web app using MeanJS stack. I have used multer plugin to upload file to server. After a lot of googling I have successfully used Multer which uploads and saves the files to uploads directory. Now Im trying to implement download the same, and I don't have an idea to do this. I have followed two methods:

  1. <a target="_self" href="/uploads/{{eachDocument.modifiedFileName}}" download="{{eachDocument.fileName}}">{{eachDocument.fileName}}</a>
  2. Have used a route in the express server controller, as given in http://expressjs.com/api.html#res.download

Using the method #1 application never downloads the file with an error "Not a file", because uploads is not the public directory.

Using method #2, I'm able to get the raw file content, but not sure how to save the file.

Can anyone please tell me how to implement the file download that are saved in uploads directory that were uploaded using multer.

Thanks

4

1 回答 1

1

@Sridhar Chidurala,请找到我的服务器和视图控制器代码:

我正在为服务器控制器使用以下代码:

var file = __dirname + "/../../" + results.filePath;
 res.download(file, results.filename, function (err) {
     if (err) {
     } else {
     }
  });

在视图控制器上,我发布了一些数据并根据这些数据将文件数据获取到视图中。:

$http.post(requestString, reqObject).
  success(function (response) {
    // **I get the file data here**
    console.log("success response : " + JSON.stringify(response));
   }).error(function (response) {
     console.log("error response : " + JSON.stringify(response));
   });
于 2015-04-21T00:54:13.687 回答