Example usage for com.mongodb.client.gridfs GridFSBucket uploadFromStream

List of usage examples for com.mongodb.client.gridfs GridFSBucket uploadFromStream

Introduction

In this page you can find the example usage for com.mongodb.client.gridfs GridFSBucket uploadFromStream.

Prototype

ObjectId uploadFromStream(String filename, InputStream source);

Source Link

Document

Uploads the contents of the given InputStream to a GridFS bucket.

Usage

From source file:org.hibernate.ogm.datastore.mongodb.binarystorage.GridFSStorageManager.java

License:LGPL

private void storeContentFromFieldToBinaryStorage(String bucketName, Document documentToInsert,
        String fieldName, Object documentId) {
    if (documentToInsert.containsKey(fieldName)) {
        GridFSBucket gridFSFilesBucket = getGridFSFilesBucket(mongoDatabase, bucketName);
        // We delete the previous entry, first
        deleteExistingContent(fieldName, documentId, gridFSFilesBucket);
        GridFS gridfsObject = documentToInsert.get(fieldName, GridFS.class);
        if (gridfsObject != null) {
            ObjectId uploadId = gridFSFilesBucket.uploadFromStream(fileName(fieldName, documentId),
                    gridfsObject.getInputStream());
            documentToInsert.put(fieldName, uploadId);
        }/*  ww  w.ja v a2  s. c  om*/
    }
}