如何修复休息获取,文件下载有时显示找不到文件错误
How to fix rest get, file download showing sometimes file not found error
所以我尝试使用 rest get 方法下载我之前上传的文件,但有时我会收到文件未找到错误,而其他时候它可以正常工作。不知道问题出在哪里
我也尝试了这个线程中的代码 file downloading in restful web services 并稍微修改了它但是这个代码的问题是我看不到文件的内容所以我的解决方案更好一点我觉得。
@GET
@Path("/{fileName}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadFile(@PathParam("fileName") String fileName) throws IOException
{
File ivyFile = new File(fileName);
byte[] data = ivyFile.readBinary().toByteArray();
StreamingOutput fileStream = new StreamingOutput()
{
@Override
public void write(java.io.OutputStream output)
{
try
{
output.write(data);
output.flush();
}
catch (IOException e)
{
throw new WebApplicationException("Could not Find the file: '" + fileName + "'", e);
}
}
};
return Response.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM)
.header("content-disposition", "attachment; filename = " + fileName).build();
}
我希望下载包含内容的文件并能够看到它。
编辑:
发生此错误时,我也会收到响应 200。还有这个错误:
MalformedChunkCodingException: CRLF expected at end of chunk
FacesException: org.apache.http.MalformedChunkCodingException: CRLF expected at end of chunk
Error during rendering of html dialog 'com.axonivy.connectivity.rest.FileUpload'
我找到了解决方案。问题是我的 IDE 导致下载超时。
所以我尝试使用 rest get 方法下载我之前上传的文件,但有时我会收到文件未找到错误,而其他时候它可以正常工作。不知道问题出在哪里
我也尝试了这个线程中的代码 file downloading in restful web services 并稍微修改了它但是这个代码的问题是我看不到文件的内容所以我的解决方案更好一点我觉得。
@GET
@Path("/{fileName}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadFile(@PathParam("fileName") String fileName) throws IOException
{
File ivyFile = new File(fileName);
byte[] data = ivyFile.readBinary().toByteArray();
StreamingOutput fileStream = new StreamingOutput()
{
@Override
public void write(java.io.OutputStream output)
{
try
{
output.write(data);
output.flush();
}
catch (IOException e)
{
throw new WebApplicationException("Could not Find the file: '" + fileName + "'", e);
}
}
};
return Response.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM)
.header("content-disposition", "attachment; filename = " + fileName).build();
}
我希望下载包含内容的文件并能够看到它。
编辑: 发生此错误时,我也会收到响应 200。还有这个错误:
MalformedChunkCodingException: CRLF expected at end of chunk
FacesException: org.apache.http.MalformedChunkCodingException: CRLF expected at end of chunk
Error during rendering of html dialog 'com.axonivy.connectivity.rest.FileUpload'
我找到了解决方案。问题是我的 IDE 导致下载超时。