Examples of GridFSInputFile


Examples of com.mongodb.gridfs.GridFSInputFile

        } 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");
        tags.add("Opera");
        meta.append("tags", tags);

        video.setMetaData(meta);
        video.save();

        System.out.println("Object ID in Files Collection: " +  video.get("_id"));


        System.out.println("Saved the file to MongoDB");
        System.out.println("Now lets read it back out");
View Full Code Here

Examples of com.mongodb.gridfs.GridFSInputFile

        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

Examples of com.mongodb.gridfs.GridFSInputFile

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

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

Examples of com.mongodb.gridfs.GridFSInputFile

        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();
    }
View Full Code Here

Examples of com.mongodb.gridfs.GridFSInputFile

    return item;
  }

  @Override
  public RepositoryItem createRepositoryItem() {
    GridFSInputFile dbFile = gridFS.createFile();
    dbFile.setFilename(dbFile.getId().toString());
    return createRepositoryItem(dbFile);
  }
View Full Code Here

Examples of com.mongodb.gridfs.GridFSInputFile

    // potentially data race with this unique test
    if (!gridFS.find(idQuery(id)).isEmpty()) {
      throw new DuplicateItemException(id);
    }

    GridFSInputFile dbFile = gridFS.createFile(id);
    dbFile.setId(id);
    return createRepositoryItem(dbFile);
  }
View Full Code Here

Examples of com.mongodb.gridfs.GridFSInputFile

   */
  private ObjectId saveGridFile(byte[] bytes)
  {
    try
    {
      GridFSInputFile file = DbManager.getSocial().getShareBinary().createFile(bytes);
      file.save();
      return (ObjectId) file.getId();
    }
    catch (Exception ex){}
    return null;
  }
View Full Code Here

Examples of com.mongodb.gridfs.GridFSInputFile

  private ObjectId updateGridFile(ObjectId binaryId, byte[] bytes)
  {
    try
    {
      //create new file
      GridFSInputFile file = DbManager.getSocial().getShareBinary().createFile(bytes);
      file.save();
     
      //remove old file if exists (this way if file throws an exception we don't lose the old file)
      if ( binaryId != null )
        DbManager.getSocial().getShareBinary().remove(binaryId);
     
      return (ObjectId) file.getId();
    }
    catch (Exception ex){}
    return binaryId;
  }
View Full Code Here

Examples of com.mongodb.gridfs.GridFSInputFile

        new DbJob() {

            @Override
            public Object doRun() throws IOException {
                final GridFSInputFile file = getGridFS().createFile(src);
                if (!fileName.isEmpty()) {
                    file.setFilename(fileName);
                }
                if (!contentType.isEmpty()) {
                    file.setContentType(contentType);
                }
                if (metadata != null) {
                    file.setMetaData(metadata);
                }
                file.save();
                return file;
            }

            @Override
            public String getNS() {
View Full Code Here

Examples of com.mongodb.gridfs.GridFSInputFile

  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();
  }
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.