我想编写一个 Excel 并将其作为使用 Play framework 1.x
的应用程序中的响应发送给用户。但我不确定如何设置响应content-type/MIME-type
以返回doc或excel文件。
让我知 Prop 体步骤。
最佳答案
To serve binary data, such as a file stored on the server, use the renderBinary method. For example, if you have a User model with a play.db.jpa.Blob photo property, add a controller method to load the model object and render the image with the stored MIME type:
public static void userPhoto(long id) {
final User user = User.findById(id);
response.setContentTypeIfNotSet(user.photo.type());
java.io.InputStream binaryData = user.photo.get();
renderBinary(binaryData);
}
关于java - 设置 mime 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14545771/