我是一名grails初学者,并且找到了一种在 View 中查看doc / pdf文件的方法。我尝试嵌入文件,但没有输出。如何查看文件?
最佳答案
假设您不只是想要链接到服务器上的其他文件(如果这样做,Rahul的回答就很好),那么您可能想在 Controller 中考虑以下内容:
def retrieveFile() {
File fileToReturn = new File("${params.filePath}")
String filename = "whatever your filename is"
byteOutput = fileToReturn.readBytes()
response.setHeader("Content-disposition", "attachment; filename=\"${filename}\"");
outputStream << byteOutput
}
然后使用适当的文件路径链接到该文件(g.createLink或其他文件)。
关于grails - 如何在Grails应用程序中查看doc/pdf文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49538430/