我已经在本地Tomcat的服务器上工作过,现在我刚刚部署了我的应用程序到CloudBees。 除了上传文件到服务器的目录外,一切都很好。上传文件,Spring MVC + CloudBees
我有这样一段代码在我的控制器,这为我工作在localhost:
@RequestMapping("/main/admin/upload")
public ModelAndView fileUploaded(
@ModelAttribute("uploadedFile") FileUpload uploadedFile,
final HttpServletRequest request,
final HttpServletResponse response, BindingResult result) {
InputStream inputStream = null;
OutputStream outputStream = null;
String pdfDirectory = uploadedFile.getPdfDirectory();
MultipartFile file = uploadedFile.getFile();
String fileName = file.getOriginalFilename();
try {
inputStream = file.getInputStream();
String pdfFileDirectory = request.getSession().getServletContext()
.getRealPath("/")
+ "resources\\pdf\\" + pdfDirectory + "\\";
File newFile = new File(pdfFileDirectory + fileName);
if (!newFile.exists()) {
newFile.createNewFile();
}
outputStream = new FileOutputStream(newFile);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
} catch (IOException e) {
e.printStackTrace();
}
return new ModelAndView("redirect:/main/admin");
}
我不知道,如果这条线工作正常:
request.getSession().getServletContext().getRealPath("/")
我m确定文件夹被创建,因为我已经在我的eclipse项目中手动添加了它们。我还在提取到CloudBees之前手动添加了一些文件到这些文件夹,并且可以访问这些文件,但是当我尝试使用上述代码上载文件时,它不起作用。
我发现了一件事...我不确定如果作品返回这一行:/mnt/genapp/apps/7c7c897e/staxcat/install/webapp.war/resources/pdf/Facebook/有没有办法将文件添加到解压缩到war文件的应用程序中? –