Answer the question
In order to leave comments, you need to log in
How to send an object with data back to a Get request so that it is recognized as a file?
Processing the request on the server, I prescribe the headers, but it opens in the browser, and is not downloaded as a file. I want to open a dialog, save as.
server
@Get()
getHello(@Response() res) {
const data = {
firstName: 'Jack',
lastName: 'Ivanov'
}
return res
.writeHeader('Content-Type', 'text/json')
.writeHeader('Content-Disposition', 'inline; filename="123.json"')
.write(data)
.end();
}
<a href="http://localhost:3000/" target="_self">Загрузить файл</a>
Answer the question
In order to leave comments, you need to log in
Need to use attachment
@Controller('file')
export class FileController {
@Get('/')
@Header('Content-Type', 'application/octet-stream')
@Header('Content-Disposition', 'attachment; filename="123.json"')
getFile() {
return {
name: 'Jack'
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question