Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node api return file

var path = require('path');
var mime = require('mime');
var fs = require('fs');

app.get('/download', function(req, res){

  var file = __dirname + '/upload-folder/dramaticpenguin.MOV';

  var filename = path.basename(file);
  var mimetype = mime.lookup(file);

  res.setHeader('Content-disposition', 'attachment; filename=' + filename);
  res.setHeader('Content-type', mimetype);

  var filestream = fs.createReadStream(file);
  filestream.pipe(res);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: Min JavaScript Methods 
Javascript :: feet to inches 
Javascript :: setstate react 
Javascript :: why sort is not working in javascript 
Javascript :: fullscreen api 
Javascript :: react final form 
Javascript :: js opposite of startswith 
Javascript :: radio button schema mongoose 
Javascript :: Get the Middle Character 
Javascript :: javascript merging arrays 
Javascript :: array.map 
Javascript :: example of call by value and call by reference in javascript 
Javascript :: install node specific version ubuntu 
Javascript :: how to filter items in react state 
Javascript :: how to get 3rd li using jquery 
Javascript :: form status angular 
Javascript :: how to make array empty 
Javascript :: can be converted to number js 
Javascript :: angular async 
Javascript :: use different environment variables in production and development 
Javascript :: remove element array javascript 
Javascript :: loop over documents in mongoose 
Javascript :: angular chart js legend position 
Javascript :: Destructuring array and object from a nested object 
Javascript :: canvas setup 
Javascript :: useref array 
Javascript :: how to declare an array in javascript 
Javascript :: javascript split method 
Javascript :: npm ERR! code EPERM 
Javascript :: run the for loop in the html elements and show the limited elements in javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =