Search in sources :

Example 6 with LogUpload

use of com.publiccms.entities.log.LogUpload in project PublicCMS-preview by sanluan.

the class FileAdminController method upload.

/**
 * @param file
 * @param field
 * @param originalField
 * @param onlyImage
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping(value = "doUpload", method = RequestMethod.POST)
public String upload(MultipartFile file, String field, String originalField, Boolean onlyImage, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (null != file && !file.isEmpty()) {
        String originalName = file.getOriginalFilename();
        String suffix = fileComponent.getSuffix(originalName);
        String fileName = fileComponent.getUploadFileName(suffix);
        try {
            fileComponent.upload(file, siteComponent.getWebFilePath(site, fileName));
            model.put("field", field);
            model.put(field, fileName);
            if (CommonUtils.notEmpty(originalField)) {
                model.put("originalField", originalField);
                model.put(originalField, originalName);
            }
            logUploadService.save(new LogUpload(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, onlyImage, file.getSize(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
        } catch (IllegalStateException | IOException e) {
            log.error(e.getMessage(), e);
            return "common/uploadResult";
        }
    }
    return "common/uploadResult";
}
Also used : LogUpload(com.publiccms.entities.log.LogUpload) IOException(java.io.IOException) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with LogUpload

use of com.publiccms.entities.log.LogUpload in project PublicCMS-preview by sanluan.

the class UeditorAdminController method uploadScraw.

/**
 * @param file
 * @param request
 * @param session
 * @return view name
 */
@RequestMapping(params = "action=" + ACTION_UPLOAD_SCRAW)
@ResponseBody
public Map<String, Object> uploadScraw(String file, HttpServletRequest request, HttpSession session) {
    SysSite site = getSite(request);
    if (CommonUtils.notEmpty(file)) {
        byte[] data = VerificationUtils.base64Decode(file);
        String fileName = fileComponent.getUploadFileName(SCRAW_TYPE);
        File dest = new File(siteComponent.getWebFilePath(site, fileName));
        try {
            FileUtils.writeByteArrayToFile(dest, data);
            logUploadService.save(new LogUpload(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, true, dest.length(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
            Map<String, Object> map = getResultMap(true);
            map.put("size", data.length);
            map.put("title", dest.getName());
            map.put("url", fileName);
            map.put("type", SCRAW_TYPE);
            map.put("original", "scraw" + SCRAW_TYPE);
            return map;
        } catch (IllegalStateException | IOException e) {
            log.error(e.getMessage(), e);
            return getResultMap(false);
        }
    }
    return getResultMap(false);
}
Also used : LogUpload(com.publiccms.entities.log.LogUpload) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with LogUpload

use of com.publiccms.entities.log.LogUpload in project PublicCMS-preview by sanluan.

the class SysSiteAdminController method upload.

/**
 * @param file
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping(value = "doUploadLicense", method = RequestMethod.POST)
public String upload(MultipartFile file, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (ControllerUtils.verifyCustom("noright", !siteComponent.isMaster(site.getId()), model)) {
        return TEMPLATE_ERROR;
    }
    if (null != file && !file.isEmpty()) {
        try {
            fileComponent.upload(file, siteComponent.getRootPath() + CommonConstants.LICENSE_FILENAME);
            logUploadService.save(new LogUpload(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, false, file.getSize(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), CommonConstants.LICENSE_FILENAME));
            return TEMPLATE_DONE;
        } catch (IllegalStateException | IOException e) {
            log.error(e.getMessage(), e);
        }
    }
    return TEMPLATE_ERROR;
}
Also used : LogUpload(com.publiccms.entities.log.LogUpload) IOException(java.io.IOException) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LogUpload (com.publiccms.entities.log.LogUpload)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 SysSite (com.publiccms.entities.sys.SysSite)7 IOException (java.io.IOException)7 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ModelMap (org.springframework.ui.ModelMap)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 PageHandler (com.publiccms.common.handler.PageHandler)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1