Bootstrap FileInput实现图片上传功能(2)

/** * 删除文件文件 */ @RequestMapping("/edit/deleteData/{id}") @ResponseBody @Transactional(rollbackFor = Exception.class) public AjaxResult deleteData(@PathVariable("id")String id, HttpServletRequest request) throws Exception{ String key = request.getParameter("key"); Record record = recordService.getById(id); String picUrls = record.getPicUrls(); String deleteName = "https://www.jb51.net/" + key; if (picUrls.indexOf("^_^" + deleteName) > -1) { picUrls = "^_^" + picUrls.replace(deleteName, ""); } if (picUrls.indexOf(deleteName + "^_^") > -1) { picUrls = picUrls.replace(deleteName + "^_^", ""); } if (picUrls.indexOf(deleteName) > -1) { picUrls = picUrls.replace(deleteName, ""); } record.setPicUrls(picUrls); if (recordMapper.updatePicsById(record) == 1) { /** 先删除数据库中的图片路径 再删除图片存储的源文件。**/ minioUtil.removeObject(bucketName, key); return success(key); } return error(); }

修改 fileInput 源码:

self._handler($el, 'click', function () { if (!self._validateMinCount()) { return false; } self.ajaxAborted = false; self._raise('filebeforedelete', [vKey, extraData]); //noinspection JSUnresolvedVariable,JSHint $.modal.confirm("确定删除原文件?删除后不可恢复",function () { //初始化回显的图片在删除时弹出提示框确认。 if (self.ajaxAborted instanceof Promise) { self.ajaxAborted.then(function (result) { if (!result) { $.ajax(settings); } }); } else { if (!self.ajaxAborted) { $.ajax(settings); } } }) }); });

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wszpfy.html