新增类型
This commit is contained in:
+2
-1
@@ -71,7 +71,8 @@ public class FilesController {
|
||||
if(StringUtils.isNotBlank(model.getFilename())){
|
||||
filename = model.getFilename();
|
||||
}
|
||||
GridFSInputFile gridFSInputFile = fileDao.saveToGridFs(file.getInputStream(), filename, contentType);
|
||||
String type = model.getType();
|
||||
GridFSInputFile gridFSInputFile = fileDao.saveToGridFs(file.getInputStream(), filename, contentType, type);
|
||||
UniversalDto dto = UniversalDto.newDto();
|
||||
if(OpenConfig.getConfig().isProductionEnvironment()){
|
||||
dto.append("link", "http://static.fangjia.com/stc/files/" + gridFSInputFile.get("_id").toString());
|
||||
|
||||
@@ -7,6 +7,10 @@ public class FilesModel extends FangjiaApiModel {
|
||||
private MultipartFile file;
|
||||
private String contentType;
|
||||
private String filename;
|
||||
/**
|
||||
* ÎļþÀàÐÍ
|
||||
*/
|
||||
private String type;
|
||||
|
||||
public MultipartFile getFile() {
|
||||
return file;
|
||||
@@ -31,4 +35,12 @@ public class FilesModel extends FangjiaApiModel {
|
||||
public void setFilename(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.mongodb.gridfs.GridFS;
|
||||
import com.mongodb.gridfs.GridFSDBFile;
|
||||
import com.mongodb.gridfs.GridFSInputFile;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -70,6 +71,18 @@ public class FileDao {
|
||||
return fsInputFile;
|
||||
}
|
||||
|
||||
public GridFSInputFile saveToGridFs(InputStream inputStream, String filename, String contentType, String type){
|
||||
GridFSInputFile fsInputFile = gridFs.createFile(inputStream, filename);
|
||||
fsInputFile.put("contentType", contentType);
|
||||
if (StringUtils.isNotBlank(type)){
|
||||
fsInputFile.put("type", type);
|
||||
} else {
|
||||
fsInputFile.put("type", "default");
|
||||
}
|
||||
fsInputFile.save();
|
||||
return fsInputFile;
|
||||
}
|
||||
|
||||
public GridFSDBFile findByIdInGridFS(String id){
|
||||
return gridFs.findOne(new ObjectId(id));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user