简体   繁体   中英

express server does not find file to download

I am facing a strange issue, with my express server: I want download a file inside a folder that is created at run-time; this is my code:

var folder = id.toString()
          var file = [projectRoot,"/app/temp/",folder, "/registrazioni.zip"].join("")
          console.log('file',file)
          res.download(file,'registrazioni.zip')

I know that all the variables are defined, but res.download raise an error:

 { [Error: ENOENT: no such file or directory, stat '/home/giuseppe/projects/csgSAW/app/temp/undefined/registrazioni.zip']

errno: -2, code: 'ENOENT', syscall: 'stat', path: '/home/projects/csgSAW/app/temp/undefined/registrazioni.zip', expose: false, statusCode: 404, status: 404 }

where I should see the folder, got undefined, but the consolo.log just before res.download is correct, so I am very puzzled, do notr know what is wrong. I am working with node 4.2.6 and express ^4.14.0, thanks in advance

It looks like the id variable is undefined.

where I should see the folder, got undefined, but the consolo.log just before res.download is correct

There is no way the string is correct in the console.log line, but not below it. If that really is the case, something must have changed the string to replace the id with 'undefined'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM