Java 类com.mongodb.gridfs.GridFSFile 实例源码

项目:metadatamanagement    文件:DataSetAttachmentService.java   
/**
 * Save the attachment for a data set. 
 * @param metadata The metadata of the attachment.
 * @return The GridFs filename.
 * @throws IOException thrown when the input stream is not closable
 */
public String createDataSetAttachment(MultipartFile multipartFile,
    DataSetAttachmentMetadata metadata) throws IOException {
  try (InputStream in = multipartFile.getInputStream()) {
    String currentUser = SecurityUtils.getCurrentUserLogin();
    metadata.setVersion(0L);
    metadata.setCreatedDate(LocalDateTime.now());
    metadata.setCreatedBy(currentUser);
    metadata.setLastModifiedBy(currentUser);
    metadata.setLastModifiedDate(LocalDateTime.now());
    String filename = buildFileName(metadata);
    String contentType = mimeTypeDetector.detect(multipartFile);
    GridFSFile gridFsFile = this.operations.store(in, 
        filename, contentType, metadata);
    gridFsFile.validate();
    return gridFsFile.getFilename();      
  }
}
项目:metadatamanagement    文件:InstrumentAttachmentService.java   
/**
 * Save the attachment for an instrument. 
 * @param metadata The metadata of the attachment.
 * @return The GridFs filename.
 * @throws IOException thrown when the input stream cannot be closed
 */
public String createInstrumentAttachment(MultipartFile multipartFile, 
    InstrumentAttachmentMetadata metadata) throws IOException {
  try (InputStream in = multipartFile.getInputStream()) {
    String currentUser = SecurityUtils.getCurrentUserLogin();
    metadata.setVersion(0L);
    metadata.setCreatedDate(LocalDateTime.now());
    metadata.setCreatedBy(currentUser);
    metadata.setLastModifiedBy(currentUser);
    metadata.setLastModifiedDate(LocalDateTime.now());
    String contentType = mimeTypeDetector.detect(multipartFile);
    GridFSFile gridFsFile = this.operations.store(in, 
        buildFileName(metadata), contentType, metadata);
    gridFsFile.validate();
    return gridFsFile.getFilename();      
  }
}
项目:metadatamanagement    文件:SurveyAttachmentService.java   
/**
 * Save the attachment for a survey. 
 * @param metadata The metadata of the attachment.
 * @return The GridFs filename.
 * @throws IOException thrown when the input stream is not closable
 */
public String createSurveyAttachment(MultipartFile multipartFile,
    SurveyAttachmentMetadata metadata) throws IOException {
  try (InputStream in = multipartFile.getInputStream()) {
    String currentUser = SecurityUtils.getCurrentUserLogin();
    metadata.setVersion(0L);
    metadata.setCreatedDate(LocalDateTime.now());
    metadata.setCreatedBy(currentUser);
    metadata.setLastModifiedBy(currentUser);
    metadata.setLastModifiedDate(LocalDateTime.now());
    String contentType = mimeTypeDetector.detect(multipartFile);
    String filename = buildFileName(metadata);
    GridFSFile gridFsFile = this.operations.store(in, 
        filename, contentType, metadata);
    gridFsFile.validate();
    return gridFsFile.getFilename();      
  }
}
项目:metadatamanagement    文件:StudyAttachmentService.java   
/**
 * Save the attachment for a study. 
 * @param metadata The metadata of the attachment.
 * @return The GridFs filename.
 * @throws IOException thrown when the input stream cannot be closed
 */
public String createStudyAttachment(MultipartFile multipartFile,
    StudyAttachmentMetadata metadata) throws IOException {
  try (InputStream in = multipartFile.getInputStream()) {
    String currentUser = SecurityUtils.getCurrentUserLogin();
    metadata.setVersion(0L);
    metadata.setCreatedDate(LocalDateTime.now());
    metadata.setCreatedBy(currentUser);
    metadata.setLastModifiedBy(currentUser);
    metadata.setLastModifiedDate(LocalDateTime.now());
    metadata.generateId();
    String contentType = mimeTypeDetector.detect(multipartFile);
    GridFSFile gridFsFile = this.operations.store(in, 
        StudyAttachmentFilenameBuilder.buildFileName(metadata), contentType, metadata);
    gridFsFile.validate();
    javers.commit(currentUser, metadata);
    return gridFsFile.getFilename();      
  }
}
项目:hdfs-archiver    文件:HDFSArchiver.java   
private boolean isDumpToLocal(GridFSFile file, GridFS fs){
    long limit = 0; 
    if(this.sizeToLocal.containsKey(fs.getDB().getName())){
        limit = this.sizeToLocal.get(fs.getDB().getName());
    }else {
        limit = this.sizeToLocal.get("default");
    }
    if(file == null && limit == 0){
        return true;
    }else if(file != null){
        log.debug("Check db limit, file size:" + file.getLength() + ", db:" + limit);
        return file.getLength() > limit;
    }else {
        return false;
    }       
}
项目:BIMplatform    文件:MongoGridFs.java   
public GridFSFile saveGlbFile(InputStream inputStream, String fileName, int rid, double lon, double lat) {
    DBObject metaData = new BasicDBObject("rid", rid);
    metaData.put(STORE_BIM_TYPE, STORE_GLB_FILE);
    metaData.put("rid", rid);
    metaData.put("lon", lon);
    metaData.put("lat", lat);
    return gridFsTemplate.store(inputStream, fileName, metaData);
}
项目:BIMplatform    文件:MongoGridFs.java   
public GridFSFile saveGlbOffline(InputStream inputStream, String fileName, Long id, double lon, double lat) {
    DBObject metaData = new BasicDBObject("offline", true);
    metaData.put("id", id);
    metaData.put(STORE_BIM_TYPE, STORE_GLB_FILE);
    metaData.put("lon", lon);
    metaData.put("lat", lat);
    return gridFsTemplate.store(inputStream, fileName, metaData);
}
项目:SixBox    文件:BoxServiceImpl.java   
/**
 * 上传文件
 *
 * @param fileEntity 文件实体
 * @param file       待上传文件
 * @param metaData   文件元数据
 * @throws FileNotFoundException 文件不存在
 */
@Override
public FileEntity upload(FileEntity fileEntity, File file, DBObject metaData) throws FileNotFoundException {
    // Upload to GridFS
    FileInputStream fileStream = new FileInputStream(file);
    GridFSFile uploadFile = gridFsOperations.store(fileStream, fileEntity.getFilename(), metaData);

    // Save entity to MongoDB
    fileEntity.setFileId(uploadFile.getId().toString());
    fileEntity.setUploadTime(Utils.getCurrentTimestamp());
    return fileRepository.save(fileEntity);
}
项目:kanbanboard    文件:FileStoreImpl.java   
/**
 * Method to store a file within MongoDB's GridFS.
 * @param inputStream containing the file to store.
 * @param fileName the file name under which the file is to be saved.
 * @param contentType a mime type describing the contents of the file.
 * @return a GridFSDBFile object on which an InputStream can be opened.
 */
public FSFile store(InputStream inputStream, String fileName, String contentType) {
    try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class)) {
        GridFsOperations gridOperations =
                (GridFsOperations) ctx.getBean("gridFsTemplate");
        GridFSFile file = gridOperations.store(inputStream, fileName, contentType);
        return new FSFile((ObjectId) file.getId(), fileName, contentType, file.getLength());
    }
}
项目:geeCommerce-Java-Shop-Software-and-PIM    文件:DefaultMediaAsset.java   
@Override
public String getMimeType() {
    if ((mimeType == null || mimeType.isEmpty()) && getId() != null) {
        MediaAssetService mediaAssetService = app.service(MediaAssetService.class);
        GridFSFile fsFile = mediaAssetService.getGridFsFile(getId());
        if (fsFile != null) {
            mimeType = fsFile.getContentType();
        }
    }
    return mimeType;
}
项目:metadatamanagement    文件:FileService.java   
/**
 * Save the given stream to mongo in a "temp directory" and return the final filename.
 * 
 * @param stream The bytes to save
 * @param fileName The fileName which gets prefixed with /tmp/
 * @param contentType the content type of the file
 * @return the final filename
 * @throws IOException thrown when the input stream cannot be closed
 */
public String saveTempFile(InputStream stream, String fileName, String contentType)
    throws IOException {
  try (InputStream inputStream = stream) {
    GridFSFile gridFsFile = 
        this.gridfOperations.store(inputStream, "/tmp/" + fileName, contentType);
    gridFsFile.validate();
    return gridFsFile.getFilename();      
  }
}
项目:metadatamanagement    文件:QuestionImageService.java   
/**
 * This method save an image into GridFS/MongoDB based on a byteArrayOutputStream.
 * Existing image should be deleted before saving/updating an image
 * @param questionId The id of the question to be saved
 * @return return the name of the saved image in the GridFS / MongoDB.
 * @throws IOException Thrown when the input stream cannot be closed
 */
public String saveQuestionImage(MultipartFile multipartFile,
    String questionId) throws IOException {
  try (InputStream in = multipartFile.getInputStream()) {
    String contentType = mimeTypeDetector.detect(multipartFile);
    GridFSFile gridFsFile = this.operations.store(in, 
        "/questions/" + questionId, contentType);
    gridFsFile.validate();
    return gridFsFile.getFilename();      
  }
}
项目:metadatamanagement    文件:SurveyResponseRateImageService.java   
/**
 * This method save an image into GridFS/MongoDB based on a byteArrayOutputStream.
 * Existing image should be deleted before saving/updating an image
 * @param surveyId The id of the question to be saved
 * @return return the name of the saved image in the GridFS / MongoDB.
 * @throws IOException thrown if the input stream cannot be closed
 */
public String saveSurveyImage(MultipartFile multipartFile,
    String surveyId, String fileName) throws IOException {
  try (InputStream in = multipartFile.getInputStream()) {
    String relativePathWithName = "/surveys/" + surveyId + "/" + fileName;
    String contentType = mimeTypeDetector.detect(multipartFile);
    GridFSFile gridFsFile = this.operations.store(in, relativePathWithName, contentType);
    gridFsFile.validate();

    return gridFsFile.getFilename();      
  }
}
项目:socialDocumentLibrary    文件:BookRepositoryMongoImpl.java   
@Override
public Book addPage(String bookId, Page page) {
    Book readBook = readBook(bookId,INVALID_PAGINATION_PARAMITER,INVALID_PAGINATION_PARAMITER);
    GridFSFile store = gridFsTemplate.store(new ByteArrayInputStream(page.getBytes()), page.getFileName());
    Book book = BookBuilder.newBookBuilder(readBook).addPage(fileNameToindex(page), String.valueOf(store.getId())).build();

    mongoTemplate.save(book);
    return book;
}
项目:kurento-java    文件:MongoRepositoryItem.java   
private MongoRepositoryItem(MongoRepository repository, GridFSFile dbFile, State state) {

    super(dbFile.getId().toString(), state, loadAttributes(dbFile), repository);

    this.dbFile = dbFile;
    // don't call ours setMetadata(...)
    super.setMetadata(new HashMap<String, String>());
  }
项目:flypost    文件:ImageUploadApplication.java   
void setImage(String id, MultipartFile image, Set<String> tokens) throws IOException {
    Zettl zettl = mongoOperations.findById(id, Zettl.class);
    deleteOldImage(zettl, tokens);
    GridFSFile gridFSFile = gridFsOperations.store(image.getInputStream(), image.getName(), image.getContentType());
    zettl.setImageId(gridFSFile.getId().toString());
    zettlUpdater.save(zettl, tokens);
}
项目:BIMplatform    文件:MongoGridFs.java   
/**
 * 
 * @param inputStream
 * @param fileName
 */
public GridFSFile saveSourceIfcFile(InputStream inputStream, String fileName) {
    DBObject metaData = new BasicDBObject();
    metaData.put(STORE_BIM_TYPE, STORE_IFC_FILE);
    return gridFsTemplate.store(inputStream, fileName);
}
项目:BIMplatform    文件:MongoGridFs.java   
public GridFSFile saveIfcModel(InputStream inputStream, String fileName, int rid) {
    DBObject metaData = new BasicDBObject("rid", rid);
    metaData.put(STORE_BIM_TYPE, STORE_IFC_MODEL);
    metaData.put("rid", rid);
    return gridFsTemplate.store(inputStream, fileName, metaData);
}
项目:hawkbit-extensions    文件:GridFsArtifact.java   
/**
 * @param dbFile
 */
public GridFsArtifact(final GridFSFile dbFile) {
    super(dbFile.getId().toString(), new DbArtifactHash(dbFile.getFilename(), dbFile.getMD5()), dbFile.getLength(),
            dbFile.getContentType());
    this.dbFile = dbFile;
}
项目:jSynapse    文件:ContentRepositoryImpl.java   
@Override
public String upload(InputStream content, String fileName, String contentType) {
    GridFSFile file = gridFsTemplate.store(content, fileName, contentType);
    return file.getId().toString();
}
项目:ymate-platform-v2    文件:MongoGridFSSession.java   
public GridFSFile upload(GridFSFileBuilder inputFile) throws Exception {
    GridFSInputFile _inFile = inputFile.build(this);
    _inFile.save();
    return _inFile;
}
项目:crowdsource    文件:ProjectAttachmentRepository.java   
public AttachmentValue storeAttachment(AttachmentValue fileMetadata, InputStream binaryData) {
    GridFSFile res = gridFsOperations.store(binaryData, fileMetadata.getFilename(), fileMetadata.getContentType());
    return new AttachmentValue(res.getId().toString(), res.getContentType(), res.getFilename(), res.getLength(), new DateTime(res.getUploadDate()));
}
项目:crowdsource    文件:ProjectAttachmentRepositoryTest.java   
private GridFSFile mockedFsDbFileFromAttachmentValue(AttachmentValue input) {
    return new TestGridFsFile(input.getContentType(), input.getCreated().getMillis(), input.getFilename(), input.getFileReference(), input.getSize());
}
项目:flypost    文件:ImageUploadApplication.java   
String storeImage(MultipartFile image) throws IOException {
    GridFSFile gridFSFile = gridFsOperations.store(image.getInputStream(), image.getName(), image.getContentType());
    return gridFSFile.getId().toString();
}
项目:hawkbit-extensions    文件:MongoDBArtifactStore.java   
/**
 * Maps a single {@link GridFSFile} to {@link AbstractDbArtifact}.
 *
 * @param tenant
 *            the tenant
 * @param dbFile
 *            the mongoDB gridFs file.
 * @return a mapped artifact from the given dbFile
 */
private static GridFsArtifact map(final GridFSFile fsFile) {
    if (fsFile == null) {
        return null;
    }

    return new GridFsArtifact(fsFile);
}
项目:kurento-java    文件:MongoRepositoryItem.java   
private static RepositoryItemAttributes loadAttributes(GridFSFile file) {

    RepositoryItemAttributes attributes = new RepositoryItemAttributes();

    attributes.setContentLength(file.getLength());
    attributes.setLastModified(file.getUploadDate().getTime());
    attributes.setMimeType(file.getContentType());

    return attributes;
  }