Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文件上传的问题 #81

Open
zuxianghuang opened this issue May 28, 2024 · 0 comments
Open

文件上传的问题 #81

zuxianghuang opened this issue May 28, 2024 · 0 comments

Comments

@zuxianghuang
Copy link

在文件上传那里,点击文件上传,报错
云存储配置 使用了 七牛,但是点击上传时
saveUploadResult(url){
this.$http({
url: this.$http.adornUrl('/sys/oss/upload'),
method: 'post',
data:{
url:url
}
}).then(({data})=>{
this.$emit('uploaded', url)
})
使用了腾讯的,方法执行到这里了,
而后台的这个接口是接收 @RequestParam("file") MultipartFile file 导致报错
/**
* 上传文件
*/
@PostMapping("/upload")
@RequiresPermissions("sys:oss:all")
@operation(summary = "上传文件到OSS")
public R upload(@RequestParam("file") MultipartFile file) throws Exception {
if (file.isEmpty()) {
throw new RRException("上传文件不能为空");
}

    //上传文件
    String suffix = Objects.requireNonNull(file.getOriginalFilename()).substring(file.getOriginalFilename().lastIndexOf("."));
    String url = Objects.requireNonNull(OSSFactory.build()).uploadSuffix(file.getBytes(), suffix);

    //保存文件信息
    SysOssEntity ossEntity = new SysOssEntity();
    ossEntity.setUrl(url);
    ossEntity.setCreateDate(new Date());
    sysOssService.save(ossEntity);

    return R.ok().put("url", url);
} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant