Example usage for org.springframework.web.multipart MultipartHttpServletRequest getContextPath

List of usage examples for org.springframework.web.multipart MultipartHttpServletRequest getContextPath

Introduction

In this page you can find the example usage for org.springframework.web.multipart MultipartHttpServletRequest getContextPath.

Prototype

public String getContextPath();

Source Link

Document

Returns the portion of the request URI that indicates the context of the request.

Usage

From source file:com.glaf.core.util.RequestUtils.java

/**
 * request??/*from   w w  w  .j  a v a2 s.  c om*/
 * 
 * @param request
 * @return
 */
public static Map<String, Object> getParameterMap(MultipartHttpServletRequest request) {
    Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
    dataMap.put("contextPath", request.getContextPath());
    Enumeration<?> enumeration = request.getParameterNames();
    while (enumeration.hasMoreElements()) {
        String paramName = (String) enumeration.nextElement();
        String paramValue = getParameter(request, paramName);
        if (StringUtils.isNotEmpty(paramName) && StringUtils.isNotEmpty(paramValue)) {
            if (paramValue.equalsIgnoreCase("null")) {
                continue;
            }
            dataMap.put(paramName, paramValue);
            String tmp = paramName.trim().toLowerCase();
            if (tmp.indexOf("date") > 0) {
                try {
                    Date date = DateUtils.toDate(paramValue);
                    dataMap.put(paramName, date);
                } catch (Exception ex) {
                }
            } else if (tmp.startsWith("x_encode_")) {
                String name = StringTools.replace(paramName, "x_encode_", "");
                dataMap.put(name, decodeString(paramValue));
            }
        }
    }
    return dataMap;
}

From source file:de.whs.poodle.controllers.ImageController.java

@RequestMapping(value = "/instructor/images/{courseId}", method = RequestMethod.POST)
@ResponseBody // send the response directly to the client instead of rendering an HTML page
public String uploadImage(@ModelAttribute Instructor instructor, @PathVariable int courseId,
        @RequestParam int CKEditorFuncNum, MultipartHttpServletRequest request) throws IOException {
    InputStream in = null;/*from   w  ww.j a va  2s . co  m*/

    try {
        String filename = request.getFileNames().next();
        MultipartFile multipartFile = request.getFile(filename);
        String originalFilename = multipartFile.getOriginalFilename();

        String mimetype = multipartFile.getContentType();
        in = multipartFile.getInputStream();
        long length = multipartFile.getSize();

        UploadedImage image = new UploadedImage();
        image.setCourseId(courseId);
        image.setInstructor(instructor);
        image.setFilename(originalFilename);
        image.setMimeType(mimetype);

        imageRepo.uploadImage(image, in, length);

        String path = request.getContextPath() + "/images/" + image.getId();

        return generateResponse(CKEditorFuncNum, path, null);

    } catch (Exception e) {
        log.error("Error uploading image", e);
        return generateResponse(CKEditorFuncNum, null, "Fehler beim Upload");
    } finally {
        if (in != null)
            in.close();
    }
}

From source file:com.cami.web.controller.uploadController.java

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public @ResponseBody String upload(MultipartHttpServletRequest request, HttpServletResponse response) {

    //0. notice, we have used MultipartHttpServletRequest

    //1. get the files from the request object
    Iterator<String> itr = request.getFileNames();

    MultipartFile mpf = request.getFile(itr.next());
    System.out.println(mpf.getOriginalFilename() + " uploaded!");

    try {/*from  w  ww. jav  a2  s  . c  om*/
        //just temporary save file info into ufile
        ufile.length = mpf.getBytes().length;
        ufile.bytes = mpf.getBytes();
        ufile.type = mpf.getContentType();
        ufile.name = mpf.getOriginalFilename();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //2. send it back to the client as <img> that calls get method
    //we are using getTimeInMillis to avoid server cached image 

    return "<img src='" + request.getContextPath() + "/upload/get/" + Calendar.getInstance().getTimeInMillis()
            + "' />";

}