spring boot 在fastdfs文件上传大小限制

因图片上传只能上传1M大小的图片,通过度娘获得更改Nginx中的限制,但是更改没有获得预期结果,继续查找可以改变MultipartFile 的限制:

修改启动类


上传代码:


工具类:

package com.steward.commons;                                                                                                                                                          
                                                                                                                                                                                      
import com.github.tobato.fastdfs.domain.StorePath;                                                                                                                                    
import com.github.tobato.fastdfs.exception.FdfsUnsupportStorePathException;                                                                                                           
import com.github.tobato.fastdfs.service.FastFileStorageClient;                                                                                                                       
import org.apache.commons.io.FilenameUtils;                                                                                                                                           
import org.apache.commons.lang3.StringUtils;                                                                                                                                          
import org.slf4j.Logger;                                                                                                                                                              
import org.slf4j.LoggerFactory;                                                                                                                                                       
import org.springframework.beans.factory.annotation.Autowired;                                                                                                                        
import org.springframework.stereotype.Component;                                                                                                                                      
import org.springframework.web.multipart.MultipartFile;                                                                                                                               
                                                                                                                                                                                      
import java.io.ByteArrayInputStream;                                                                                                                                                  
import java.io.IOException;                                                                                                                                                           
import java.nio.charset.Charset;                                                                                                                                                      
                                                                                                                                                                                      
/**                                                                                                                                                                                   
 * <p>                                                                                                                                                                                
 * Description: FastDFS文件上传下载包装类                                                                                                                                                      
 * </p>                                                                                                                                                                               
 * <p>                                                                                                                                                                                
 * Copyright: Copyright (c) 2016                                                                                                                                                      
 * </p>                                                                                                                                                                               
 */                                                                                                                                                                                   
@Component                                                                                                                                                                            
public class FastDFSClientWrapper {                                                                                                                                                   
                                                                                                                                                                                      
private final Logger logger = LoggerFactory.getLogger(FastDFSClientWrapper.class);                                                                                                
                                                                                                                                                                                      
@Autowired                                                                                                                                                                        
private FastFileStorageClient storageClient;                                                                                                                                      
                                                                                                                                                                                      
/**                                                                                                                                                                               
* 上传文件                                                                                                                                                                           
*                                                                                                                                                                                
* @param file                                                                                                                                                                    
*            文件对象                                                                                                                                                                
* @return 文件访问地址                                                                                                                                                                 
* @throws IOException                                                                                                                                                            
*/                                                                                                                                                                               
public String uploadFile(MultipartFile file) throws IOException {                                                                                                                 
StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(),                                                                                         
FilenameUtils.getExtension(file.getOriginalFilename()), null);                                                                                                        
return getResAccessUrl(storePath);                                                                                                                                            
}                                                                                                                                                                                 
                                                                                                                                                                                      
/**                                                                                                                                                                               
* 将一段字符串生成一个文件上传                                                                                                                                                                 
*                                                                                                                                                                                
* @param content                                                                                                                                                                 
*            文件内容                                                                                                                                                                
* @param fileExtension                                                                                                                                                           
* @return                                                                                                                                                                        
*/                                                                                                                                                                               
public String uploadFile(String content, String fileExtension) {                                                                                                                  
byte[] buff = content.getBytes(Charset.forName("UTF-8"));                                                                                                                     
ByteArrayInputStream stream = new ByteArrayInputStream(buff);                                                                                                                 
StorePath storePath = storageClient.uploadFile(stream, buff.length, fileExtension, null);                                                                                     
return getResAccessUrl(storePath);                                                                                                                                            
}                                                                                                                                                                                 
                                                                                                                                                                                      
// 封装图片完整URL地址                                                                                                                                                                    
private String getResAccessUrl(StorePath storePath) {                                                                                                                             
String fileUrl = storePath.getFullPath();                                                                                                                                     
return fileUrl;                                                                                                                                                               
}                                                                                                                                                                                 
                                                                                                                                                                                      
/**                                                                                                                                                                               
* 传图片并同时生成一个缩略图 "JPG", "JPEG", "PNG", "GIF", "BMP", "WBMP"                                                                                                                       
*                                                                                                                                                                                
* @param file                                                                                                                                                                    
*            文件对象                                                                                                                                                                
* @return 文件访问地址                                                                                                                                                                 
* @throws IOException                                                                                                                                                            
*/                                                                                                                                                                               
public String uploadImageAndCrtThumbImage(MultipartFile file) throws IOException {                                                                                                
StorePath storePath = storageClient.uploadImageAndCrtThumbImage(file.getInputStream(), file.getSize(),                                                                        
FilenameUtils.getExtension(file.getOriginalFilename()), null);                                                                                                        
return getResAccessUrl(storePath);                                                                                                                                            
}                                                                                                                                                                                 
                                                                                                                                                                                      
/**                                                                                                                                                                               
* 删除文件                                                                                                                                                                           
*                                                                                                                                                                                
* @param fileUrl                                                                                                                                                                 
*            文件访问地址                                                                                                                                                              
* @return                                                                                                                                                                        
*/                                                                                                                                                                               
public void deleteFile(String fileUrl) {                                                                                                                                          
if (StringUtils.isEmpty(fileUrl)) {                                                                                                                                           
return;                                                                                                                                                                   
}                                                                                                                                                                             
try {                                                                                                                                                                         
StorePath storePath = StorePath.praseFromUrl(fileUrl);                                                                                                                    
storageClient.deleteFile(storePath.getGroup(), storePath.getPath());                                                                                                      
} catch (FdfsUnsupportStorePathException e) {                                                                                                                                 
logger.warn(e.getMessage());                                                                                                                                              
}                                                                                                                                                                             
}                                                                                                                                                                                 
}                                                                                                                                                                                     
                                                                                                                                                                                      




  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值