https://issues.apache.org/bugzilla/show_bug.cgi?id=56726

--- Comment #4 from Nawazish <md.nawazish.k...@gmail.com> ---
(In reply to Christopher Schultz from comment #1)
> Perhaps your access is denied to that file/directory. Bug 54971 seems
> unrelated unless you think this has something to do with relative versus
> absolute path specifications.
> 
> If you want any reasonable reply, you need to:
> 
> a) post your multipart configuration (whether from web.xml or @Annotations)
> b) tell us the effective user under which Tomcat is running
> c) give details about the ownership of the directories mentioned in your
> error report attachment

@Christopher Schultz

Thanks for your note. Following are the details as required:

a) We are using Spring's DispatcherServlet as the front-controller to the
application so the web.xml looks like this:
<servlet>
  <servlet-name>spring</servlet-name>

  <servlet-class>
     org.springframework.web.servlet.DispatcherServlet
  </servlet-class>

    <multipart-config>
        <max-file-size>10485760</max-file-size>
        <max-request-size>20971520</max-request-size>
        <file-size-threshold>5242880</file-size-threshold>
        </multipart-config>
    <load-on-startup>1</load-on-startup>
</servlet>

b) By "effective user" I understand the Operating System. If so, then Tomcat is
running on Windows 7. Albeit, Tomcat is launched/handled from Eclipse IDE.

c) The directories are given "Full Control".

Hope these were useful. Looking forward for your reply.

(In reply to Konstantin Kolinko from comment #2)
> The Manager web application uses this API and is known to work successfully.
> 
> See the following line in HTMLManagerServlet:
> > warPart.write(file.getAbsolutePath());
> 
> 
> I think you are doing something wrong. Ask for help on the users mailing
> list, or provide specific steps (and working example) to reproduce this
> issue.

@Konstantin Kolinko

Below I provide the specific steps and working code which is failing to
reproduce the issue:

// Step1: Create String representation of directory structure where the
uploaded // file would be saved. Get "real path" to the appliation.
// Below, "authRole" and "uid" are String variables. Their values are captured
// from Session object. "directoryLocation" returns the String representation
// of actual location where the file would be uploaded. 
String appPath = request.getServletContext().getRealPath("");

        Date date = new Date();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
        String attachmentDate = fmt.format(date).toString();

String directoryLocation = appPath + File.separator + "attachments"
            + File.separator + authRole + File.separator + uid
                + File.separator + attachmentDate;

        return directoryLocation;
    }

//step2: Create directory structure, if one does not exist.
    public static void saveUploadedFileToDisk(HttpServletRequest request,
            String directoryLocation)
            throws IOException, ServletException {
        File fileObject = new File(directoryLocation);
        if (!fileObject.exists()) {
            fileObject.mkdirs();
        }

//step3: Get all the parts from HttpServletRequest and get the name of the 
//uploaded files from each part.
//step4: "write" the part to the pre-created location.

        for (Part part : request.getParts()) {
            String fileName = getFileName(part);
            if (fileName != null) {
                part.write(directoryLocation + File.separator + fileName);
            }
        }
    }
}

private static String getFileName(Part part) {
        String headerContent = part.getHeader("content-disposition");
        String[] s = headerContent.split(";");
        for (String str : s) {
            if (str.trim().startsWith("filename")) {
                return str.substring(str.indexOf("=") + 2, str.length() - 1);
            }
        }
        return null;
    }

Hope that would be helpful. Let me know for further elaboration.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to