angular-filemanager
angular-filemanager copied to clipboard
Upload file doesn't working
When I try to upload file from disk i gives me error like this: Servlet.service() for servlet [dispatcher] in context with path [/ATMReporting-web] threw exception [Cannot write file] with root cause java.lang.Exception: write error I'm using java servlet from this address: https://github.com/joni2back/angular-filemanager/blob/master/bridges/java/AngularFileManagerServlet.java
Hi, seems to be permissions problem... are you using Linux in the upload destination?
Hi,thanks for replay. No,i'm not using Linux.Im using Windows.. I'm trying to implement filemanager in my application,but now I get error like this:
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/ATMReporting-web] threw exception [Cannot write file] with root cause java.lang.Exception: file size = 0 at rs.mypackage.atmreporting.web.controller.reports.ReportsController.uploadFile(ReportsController.java:1010) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483)
Reports.Controller,java:1010 looks like this: if (files.size() == 0) { throw new Exception("file size = 0");
So it says that file is empty but i did not choose a empty file.. I don't know why is this happening..Everything else(newfolder button,rename,delete button..) is functioning just fine.. Here is my controller(i'm using spring framework in my app): @RequestMapping(value="/doUpload",method=RequestMethod.POST) private void uploadFile(HttpServletRequest request, HttpServletResponse response) throws ServletException { // URL: $config.uploadUrl, Method: POST, Content-Type: multipart/form-data // Unlimited file upload, each item will be enumerated as file-1, file-2, etc. // [$config.uploadUrl]?destination=/public_html/image.jpg&file-1={..}&file-2={...} DocumentationSettings settings=new DocumentationSettings(logger,REPOSITORY_BASE_URL,DATE_FORMAT,context); try { String destination = null; Map<String, InputStream> files = new HashMap<String, InputStream>();
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : items) {
if (item.isFormField()) {
// Process regular form field (input type="text|radio|checkbox|etc", select, etc).
if ("destination".equals(item.getFieldName())) {
destination = item.getString();
}
} else {
// Process form file field (input type="file").
files.put(item.getName(),item.getInputStream());
}
}
if (files.size() == 0) {
throw new Exception("file size = 0");
} else {
for (Map.Entry<String, InputStream> fileEntry : files.entrySet()) {
File f = new File(settings.context.getRealPath(REPOSITORY_BASE_URL + destination), fileEntry.getKey());
System.out.println("settings.context.getRealPath=="+settings.context.getRealPath(REPOSITORY_BASE_URL + destination));
if (!write(fileEntry.getValue(), f)) {
throw new Exception("write error");
}
}
}
} catch (FileUploadException e) {
throw new ServletException("Cannot parse multipart request: DiskFileItemFactory.parseRequest", e);
} catch (IOException e) {
throw new ServletException("Cannot parse multipart request: item.getInputStream", e);
} catch (Exception e) {
throw new ServletException("Cannot write file", e);
}
}
@RequestMapping(value="/doUpload",method=RequestMethod.POST) private void uploadFile(HttpServletRequest request, HttpServletResponse response) throws ServletException { // URL: $config.uploadUrl, Method: POST, Content-Type: multipart/form-data // Unlimited file upload, each item will be enumerated as file-1, file-2, etc. // [$config.uploadUrl]?destination=/public_html/image.jpg&file-1={..}&file-2={...} DocumentationSettings settings=new DocumentationSettings(logger,REPOSITORY_BASE_URL,DATE_FORMAT,context); try { String destination = null; Map<String, InputStream> files = new HashMap<String, InputStream>();
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : items) {
if (item.isFormField()) {
// Process regular form field (input type="text|radio|checkbox|etc", select, etc).
if ("destination".equals(item.getFieldName())) {
destination = item.getString();
}
} else {
// Process form file field (input type="file").
files.put(item.getName(),item.getInputStream());
}
}
System.out.println("fajlovi"+files);
if (files.size() == 0) {
throw new Exception("file size = 0");
} else {
for (Map.Entry<String, InputStream> fileEntry : files.entrySet()) {
File f = new File(settings.context.getRealPath(REPOSITORY_BASE_URL + destination), fileEntry.getKey());
System.out.println("FILE.ENTRY.GET KEY="+fileEntry.getKey());
System.out.println("settings.context.getRealPath=="+settings.context.getRealPath(REPOSITORY_BASE_URL + destination));
System.out.println("FAJL JE"+f);
if (!write(fileEntry.getValue(), f)) {
throw new Exception("write error");
}
}
}
} catch (FileUploadException e) {
throw new ServletException("Cannot parse multipart request: DiskFileItemFactory.parseRequest", e);
} catch (IOException e) {
throw new ServletException("Cannot parse multipart request: item.getInputStream", e);
} catch (Exception e) {
throw new ServletException("Cannot write file", e);
}
}