java - 创建存储在本地服务器中的文件的 URI 并以 REST JSON 格式发送 URL
问题描述
我想将文件从我的应用程序保存到服务器,然后读取文件的位置并在请求 JSON 中发送 URL,但是每次运行此代码时,我都会收到此错误异常:没有当前的 ServletRequestAttributes。
public String createFile(){
try {
String filename = "output.log";
Path path = Paths.get(filename);
byte[] bytes = contents.getBytes();
Files.write(path, bytes);
} catch (IOException ex) {
ex.getStackTrace();
}
String URL = getFileURL(filename);
}
public String getFileURL(String fileName){
String fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath()
.path("/downloadFile/")
.path(fileName)
.toUriString();
return fileDownloadUri;
}
解决方案
推荐阅读
- excel - Loc 函数在 pandas 中不起作用(我的 df.loc 命令不起作用)
- python - Django 的 queryset.aggregate max() 在 9 之后遇到问题
- sql - Oracle - 都获取 XML 日期字符串并将其转换为日期
- r - Linux 环境中默认的 .RData 工作区保存在哪里?
- python - 具有 350 个点的 3D 散点图上的颜色代码点
- python-3.x - 应用程序引擎无法部署具有大型数据框的应用程序
- xamarin.forms - Xamarin ScrollView:HorizontalScrollBarVisibility 在 Android 上被忽略
- java - 如果 div 类出现在 id 之后,如何提取数据?
- mongodb - 在文档中组合两个数组
- java - 从各种 EditText 字段中获取文本