本文整理汇总了Java中io.vertx.core.http.HttpServerResponse.sendFile方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerResponse.sendFile方法的具体用法?Java HttpServerResponse.sendFile怎么用?Java HttpServerResponse.sendFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.http.HttpServerResponse
的用法示例。
在下文中一共展示了HttpServerResponse.sendFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendFile
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
private void sendFile(RoutingContext routingContext, String fileName, File saneFile) {
HttpServerResponse response = routingContext.response();
response.putHeader("Content-Description", "File Transfer");
response.putHeader("Content-Type", "application/octet-stream");
response.putHeader("Content-Disposition", "attachment; filename=" + fileName); // @TODO: don't trust this name?
response.putHeader("Content-Transfer-Encoding", "binary");
response.putHeader("Expires", "0");
response.putHeader("Pragma", "Public");
response.putHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.putHeader("Content-Length", "" + saneFile.length());
response.sendFile(saneFile.getAbsolutePath());
}
示例2: write
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void write(String path, HttpServerRequest request, HttpServerResponse response) {
if (fileExists(context, path)) {
response.sendFile(path);
}
else {
response.setStatusCode(Response.Status.NOT_FOUND.getStatusCode());
}
}