Java Code Examples for com.ruoyi.common.utils.file.FileUploadUtils

The following examples show how to use com.ruoyi.common.utils.file.FileUploadUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: supplierShop   Source File: CommonController.java    License: MIT License 6 votes vote down vote up
/**
 * 通用上传请求
 */
@PostMapping("/common/upload")
@ResponseBody
public AjaxResult uploadFile(MultipartFile file) throws Exception
{
    try
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String url = serverConfig.getUrl() + fileName;
        AjaxResult ajax = AjaxResult.success();
        ajax.put("fileName", fileName);
        ajax.put("url", url);
        return ajax;
    }
    catch (Exception e)
    {
        return AjaxResult.error(e.getMessage());
    }
}
 
Example 2
Source Project: RuoYi-Vue   Source File: CommonController.java    License: MIT License 6 votes vote down vote up
/**
 * 通用上传请求
 */
@PostMapping("/common/upload")
public AjaxResult uploadFile(MultipartFile file) throws Exception
{
    try
    {
        // 上传文件路径
        String filePath = RuoYiConfig.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String url = serverConfig.getUrl() + fileName;
        AjaxResult ajax = AjaxResult.success();
        ajax.put("fileName", fileName);
        ajax.put("url", url);
        return ajax;
    }
    catch (Exception e)
    {
        return AjaxResult.error(e.getMessage());
    }
}
 
Example 3
Source Project: RuoYi   Source File: CommonController.java    License: Apache License 2.0 6 votes vote down vote up
@PostMapping("/common/upload")
@ResponseBody
@ApiOperation(value = "通用文件上传")
@ApiImplicitParams({
        @ApiImplicitParam(name = "fileName",value = "文件名",required = true),
        @ApiImplicitParam(name = "delete",value = "是否删除临时文件",required = true,dataType ="boolean")
})
public AjaxResult uploadFile(MultipartFile file){
    try
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String url = serverConfig.getUrl() + UPLOAD_PATH + fileName;
        AjaxResult ajax = AjaxResult.success();
        ajax.put("fileName", fileName);
        ajax.put("url", url);
        return ajax;
    }
    catch (Exception e)
    {
        return AjaxResult.error(e.getMessage());
    }
}
 
Example 4
Source Project: RuoYi   Source File: SysProfileController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 保存头像
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PostMapping("/updateAvatar")
@ResponseBody
public AjaxResult updateAvatar(SysUser user, @RequestParam("avatarfile") MultipartFile file) {
    try {
        if (!file.isEmpty()) {
            String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file);
            user.setAvatar(avatar);
            if (userService.updateUserInfo(user) > 0) {
                setSysUser(userService.selectUserById(user.getUserId()));
                return success();
            }
        }
        return error();
    } catch (Exception e) {
        log.error("修改头像失败!", e);
        return error(e.getMessage());
    }
}
 
Example 5
Source Project: supplierShop   Source File: SysProfileController.java    License: MIT License 5 votes vote down vote up
/**
 * 保存头像
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PostMapping("/updateAvatar")
@ResponseBody
public AjaxResult updateAvatar(@RequestParam("avatarfile") MultipartFile file)
{
    SysUser currentUser = ShiroUtils.getSysUser();
    try
    {
        if (!file.isEmpty())
        {
            String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file);
            currentUser.setAvatar(avatar);
            if (userService.updateUserInfo(currentUser) > 0)
            {
                ShiroUtils.setSysUser(userService.selectUserById(currentUser.getUserId()));
                return success();
            }
        }
        return error();
    }
    catch (Exception e)
    {
        log.error("修改头像失败!", e);
        return error(e.getMessage());
    }
}