Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFS.createFile()


        // + originalFilename);
        //
        // file.transferTo(dest);

        GridFS gridFs = new GridFS(mongoTemplate.getDb(), folder);
        GridFSInputFile gfsFile = gridFs.createFile(file.getFileItem()
            .getInputStream());

        gfsFile.setFilename(originalFilename);
        gfsFile.save();
View Full Code Here


  {
    DB db = DBUtils.connectDB("localhost", 27017, "test");

    GridFS fs = new GridFS(db);
   
    GridFSInputFile inputFile = fs.createFile(new File("./foo.txt"));
    System.out.println("GridFS file: "+inputFile.getFilename());


  }
}
View Full Code Here

   
    DB mdb = this.mongoConn.getDatabase(this.collection);
    GridFS gfsFile = new GridFS(mdb, this.namespace);
   
    // Load in a GridFS file the Inptustream
    GridFSInputFile gfsInputFile = gfsFile.createFile(is);
   
    // set a filename for identification purposes. We use the previously created UUID
    gfsInputFile.setFilename(uuid);
   
    // save the file file into mongoDB and disconnect
View Full Code Here

        } catch (FileNotFoundException e) {
            System.out.println("Can't open file");
            System.exit(1);
        }

        GridFSInputFile video  = videos.createFile(inputStream, "video.mp4");

        // create some meta data for the object
        BasicDBObject meta = new BasicDBObject("description", "Jennifer Singing");
        ArrayList<String> tags = new ArrayList<String>();
        tags.add("Singing");
View Full Code Here

        return blob;
    }

    private String writeBlob(byte[] blob) {
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSInputFile gridFSInputFile = gridFS.createFile(new ByteArrayInputStream(blob), true);
        gridFSInputFile.save();
        return gridFSInputFile.getMD5();
    }
}
View Full Code Here

        if (gridFile != null) {
            is.close();
            return md5;
        }

        GridFSInputFile gridFSInputFile = gridFS.createFile(bis, true);
        gridFSInputFile.save();
        return gridFSInputFile.getMD5();
    }

    private String calculateMd5(BufferedInputStream bis) throws IOException {
View Full Code Here

        for (int i = 0; i < blob.length; i++) {
            blob[i] = (byte) i;
        }
        ByteArrayInputStream is = new ByteArrayInputStream(blob);
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSInputFile gridFSInputFile = gridFS.createFile(is, true);
        gridFSInputFile.save();
        blobId = gridFSInputFile.getMD5();
    }

    @Test
View Full Code Here

  private static ThreadLocal<MongoClient> clientLocal = new ThreadLocal<MongoClient>();
  private static ThreadLocal<DB> dbLocal = new ThreadLocal<DB>();

  public static void saveFile(String fileName, byte[] data) {
    GridFS fs = new GridFS(db());
    GridFSInputFile in = fs.createFile(data);
    in.setId(fileName);
    in.save();
  }

  public static byte[] getFile(String fileName) {
View Full Code Here

      MongoRepository mongoRepository = (MongoRepository) repository;

      GridFS gridFS = mongoRepository.getGridFS();

      GridFSInputFile file = gridFS.createFile(new File(
          "test-files/sample.txt"));

      file.setId("sample.txt");

      file.save();
View Full Code Here

            if (!databaseService.getDbList().contains(dbName)) {
                throw new DatabaseException(ErrorCodes.DB_DOES_NOT_EXISTS, "DB [" + dbName + "] DOES NOT EXIST");
            }

            GridFS gridFS = new GridFS(mongoInstance.getDB(dbName), bucketName);
            GridFSInputFile fsInputFile = gridFS.createFile(inputStream, fileData.getFileName());
            fsInputFile.setContentType(formData.getMediaType().toString());
            fsInputFile.save();
            String objectId = JSON.serialize(fsInputFile.getId());
            JSONObject obj = new JSONObject();
            obj.put("name", fsInputFile.getFilename());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.