@Override public Uri putBlob(Uri uri, Blob blob) { GridFSUploadOptions options = new GridFSUploadOptions(); Document document = JsonBsonCodec.toBson(mapper, blob.getMetadata()); options.metadata(document); GridFSUploadStream file = bucket.openUploadStream(uri.toString(), options); try { IOUtils.copy(blob.getPayload().openStream(), file); } catch (IOException e) { throw Throwables.propagate(e); } file.close(); return Uri.create("mongodb://" + databaseName + "/" + bucket.getBucketName() + "/" + file.getFileId().toString()); }
@Override public InputStream store(DownloadItem downloadItem) throws IOException, JSONException { rwl.r.lock(); try { final URI uri = downloadItem.getUri(); if (!uri.equals(this.uri)) throw new IOException("The URI does not match: " + uri + " / " + this.uri); final Document newDocument = Document.parse(downloadItem.getMetaAsJson()); newDocument.put("uri", uriString); final BsonValue id = metaCollection.replaceOne(eq("uri", uriString), newDocument, UPSERT) .getUpsertedId(); final GridFSUploadOptions options = new GridFSUploadOptions().metadata(new Document("_id", id)); contentGrid.uploadFromStream(id, uriString, downloadItem.getContentInputStream(), options); return contentGrid.openDownloadStream(id); } finally { rwl.r.unlock(); } }
private void uploadStream(SmofGridRef ref, String name, InputStream stream) { final String bucketName = ref.getBucketName(); final ObjectId id; final GridFSBucket bucket; Preconditions.checkNotNull(bucketName, "No bucket specified"); final GridFSUploadOptions options = new GridFSUploadOptions().metadata(ref.getMetadata()); bucket = pool.getBucket(bucketName); id = bucket.uploadFromStream(name, stream, options); ref.setId(id); }
@Override public Observable<ObjectId> uploadFromStream(final String filename, final AsyncInputStream source, final GridFSUploadOptions options) { return RxObservables.create(Observables.observe(new Block<SingleResultCallback<ObjectId>>() { @Override public void apply(final SingleResultCallback<ObjectId> callback) { wrapped.uploadFromStream(filename, toCallbackAsyncInputStream(source), options, callback); } }), observableAdapter); }
@Override public Observable<Success> uploadFromStream(final BsonValue id, final String filename, final AsyncInputStream source, final GridFSUploadOptions options) { return RxObservables.create(Observables.observe(new Block<SingleResultCallback<Success>>() { @Override public void apply(final SingleResultCallback<Success> callback) { wrapped.uploadFromStream(id, filename, toCallbackAsyncInputStream(source), options, voidToSuccessCallback(callback)); } }), observableAdapter); }
@Override public Publisher<ObjectId> uploadFromStream(final String filename, final AsyncInputStream source, final GridFSUploadOptions options) { return new ObservableToPublisher<ObjectId>(observe(new Block<SingleResultCallback<ObjectId>>() { @Override public void apply(final SingleResultCallback<ObjectId> callback) { wrapped.uploadFromStream(filename, toCallbackAsyncInputStream(source), options, callback); } })); }
@Override public Publisher<Success> uploadFromStream(final BsonValue id, final String filename, final AsyncInputStream source, final GridFSUploadOptions options) { return new ObservableToPublisher<Success>(observe(new Block<SingleResultCallback<Success>>() { @Override public void apply(final SingleResultCallback<Success> callback) { wrapped.uploadFromStream(id, filename, toCallbackAsyncInputStream(source), options, voidToSuccessCallback(callback)); } })); }
@Override public Publisher<ObjectId> uploadFromStream(final ClientSession clientSession, final String filename, final AsyncInputStream source, final GridFSUploadOptions options) { return new ObservableToPublisher<ObjectId>(observe(new Block<SingleResultCallback<ObjectId>>() { @Override public void apply(final SingleResultCallback<ObjectId> callback) { wrapped.uploadFromStream(clientSession, filename, toCallbackAsyncInputStream(source), options, callback); } })); }
@Override public Publisher<Success> uploadFromStream(final ClientSession clientSession, final BsonValue id, final String filename, final AsyncInputStream source, final GridFSUploadOptions options) { return new ObservableToPublisher<Success>(observe(new Block<SingleResultCallback<Success>>() { @Override public void apply(final SingleResultCallback<Success> callback) { wrapped.uploadFromStream(clientSession, id, filename, toCallbackAsyncInputStream(source), options, voidToSuccessCallback(callback)); } })); }
private GridFSUploadOptions getGridFSUploadOptions(String uniqueId, String fileName, boolean compress, long timestamp, Map<String, String> metadataMap) { Document metadata = new Document(); if (metadataMap != null) { for (String key : metadataMap.keySet()) { metadata.put(key, metadataMap.get(key)); } } metadata.put(TIMESTAMP, timestamp); metadata.put(COMPRESSED_FLAG, compress); metadata.put(DOCUMENT_UNIQUE_ID_KEY, uniqueId); metadata.put(FILE_UNIQUE_ID_KEY, getGridFsId(uniqueId, fileName)); return new GridFSUploadOptions().chunkSizeBytes(1024).metadata(metadata); }
public FileStoreBucket() { gridFSUploadOptions = new GridFSUploadOptions(); gridFSUploadOptions.chunkSizeBytes(CHUNK_SIZE_BYTES); }
@Override public GridFSUploadStream openUploadStream(final String filename, final GridFSUploadOptions options) { return new GridFSUploadStreamImpl(wrapped.openUploadStream(filename, options), observableAdapter); }
@Override public GridFSUploadStream openUploadStream(final BsonValue id, final String filename, final GridFSUploadOptions options) { return new GridFSUploadStreamImpl(wrapped.openUploadStream(id, filename, options), observableAdapter); }
@Override public GridFSUploadStream openUploadStream(final String filename) { return openUploadStream(filename, new GridFSUploadOptions()); }
@Override public GridFSUploadStream openUploadStream(final String filename, final GridFSUploadOptions options) { return new GridFSUploadStreamImpl(wrapped.openUploadStream(filename, options)); }
@Override public GridFSUploadStream openUploadStream(final BsonValue id, final String filename) { return openUploadStream(id, filename, new GridFSUploadOptions()); }
@Override public GridFSUploadStream openUploadStream(final BsonValue id, final String filename, final GridFSUploadOptions options) { return new GridFSUploadStreamImpl(wrapped.openUploadStream(id, filename, options)); }
@Override public GridFSUploadStream openUploadStream(final ClientSession clientSession, final String filename) { return openUploadStream(clientSession, filename, new GridFSUploadOptions()); }
@Override public GridFSUploadStream openUploadStream(final ClientSession clientSession, final String filename, final GridFSUploadOptions options) { return new GridFSUploadStreamImpl(wrapped.openUploadStream(clientSession, filename, options)); }
@Override public GridFSUploadStream openUploadStream(final ClientSession clientSession, final BsonValue id, final String filename) { return openUploadStream(clientSession, id, filename, new GridFSUploadOptions()); }
@Override public GridFSUploadStream openUploadStream(final ClientSession clientSession, final BsonValue id, final String filename, final GridFSUploadOptions options) { return new GridFSUploadStreamImpl(wrapped.openUploadStream(clientSession, id, filename, options)); }
@Override public Publisher<ObjectId> uploadFromStream(final String filename, final AsyncInputStream source) { return uploadFromStream(filename, source, new GridFSUploadOptions()); }
@Override public Publisher<Success> uploadFromStream(final BsonValue id, final String filename, final AsyncInputStream source) { return uploadFromStream(id, filename, source, new GridFSUploadOptions()); }
@Override public Publisher<ObjectId> uploadFromStream(final ClientSession clientSession, final String filename, final AsyncInputStream source) { return uploadFromStream(clientSession, filename, source, new GridFSUploadOptions()); }
@Override public Publisher<Success> uploadFromStream(final ClientSession clientSession, final BsonValue id, final String filename, final AsyncInputStream source) { return uploadFromStream(clientSession, id, filename, source, new GridFSUploadOptions()); }
/** * Opens a AsyncOutputStream that the application can write the contents of the file to. * <p> * As the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When * the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection * document is created in the files collection. * </p> * * @param filename the filename for the stream * @param options the GridFSUploadOptions * @return the GridFSUploadStream that provides the ObjectId for the file to be uploaded and the Stream to which the * application will write the contents. */ GridFSUploadStream openUploadStream(String filename, GridFSUploadOptions options);
/** * Opens a AsyncOutputStream that the application can write the contents of the file to. * <p> * As the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When * the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection * document is created in the files collection. * </p> * * @param id the custom id value of the file * @param filename the filename for the stream * @param options the GridFSUploadOptions * @return the GridFSUploadStream that provides the ObjectId for the file to be uploaded and the Stream to which the * application will write the contents. */ GridFSUploadStream openUploadStream(BsonValue id, String filename, GridFSUploadOptions options);
/** * Uploads the contents of the given {@code AsyncInputStream} to a GridFS bucket. * <p> * Reads the contents of the user file from the {@code source} and uploads it as chunks in the chunks collection. After all the * chunks have been uploaded, it creates a files collection document for {@code filename} in the files collection. * </p> * * @param filename the filename for the stream * @param source the Stream providing the file data * @param options the GridFSUploadOptions * @return an observable with a single element, the ObjectId of the uploaded file. */ Observable<ObjectId> uploadFromStream(String filename, AsyncInputStream source, GridFSUploadOptions options);
/** * Uploads the contents of the given {@code AsyncInputStream} to a GridFS bucket. * <p> * Reads the contents of the user file from the {@code source} and uploads it as chunks in the chunks collection. After all the * chunks have been uploaded, it creates a files collection document for {@code filename} in the files collection. * </p> * * @param id the custom id value of the file * @param filename the filename for the stream * @param source the Stream providing the file data * @param options the GridFSUploadOptions * @return an observable with a single element, representing when the successful upload of the source. */ Observable<Success> uploadFromStream(BsonValue id, String filename, AsyncInputStream source, GridFSUploadOptions options);
/** * Opens a AsyncOutputStream that the application can write the contents of the file to. * <p> * As the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When * the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection * document is created in the files collection. * </p> * * @param clientSession the client session with which to associate this operation * @param filename the filename for the stream * @param options the GridFSUploadOptions * @return the GridFSUploadStream that provides the ObjectId for the file to be uploaded and the Stream to which the * application will write the contents. * @mongodb.server.release 3.6 * @since 1.7 */ GridFSUploadStream openUploadStream(ClientSession clientSession, String filename, GridFSUploadOptions options);
/** * Opens a AsyncOutputStream that the application can write the contents of the file to. * <p> * As the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When * the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection * document is created in the files collection. * </p> * * @param clientSession the client session with which to associate this operation * @param id the custom id value of the file * @param filename the filename for the stream * @param options the GridFSUploadOptions * @return the GridFSUploadStream that provides the ObjectId for the file to be uploaded and the Stream to which the * application will write the contents. * @mongodb.server.release 3.6 * @since 1.7 */ GridFSUploadStream openUploadStream(ClientSession clientSession, BsonValue id, String filename, GridFSUploadOptions options);
/** * Uploads the contents of the given {@code AsyncInputStream} to a GridFS bucket. * <p> * Reads the contents of the user file from the {@code source} and uploads it as chunks in the chunks collection. After all the * chunks have been uploaded, it creates a files collection document for {@code filename} in the files collection. * </p> * * @param filename the filename for the stream * @param source the Stream providing the file data * @param options the GridFSUploadOptions * @return a publisher with a single element, the ObjectId of the uploaded file. */ Publisher<ObjectId> uploadFromStream(String filename, AsyncInputStream source, GridFSUploadOptions options);
/** * Uploads the contents of the given {@code AsyncInputStream} to a GridFS bucket. * <p> * Reads the contents of the user file from the {@code source} and uploads it as chunks in the chunks collection. After all the * chunks have been uploaded, it creates a files collection document for {@code filename} in the files collection. * </p> * * @param id the custom id value of the file * @param filename the filename for the stream * @param source the Stream providing the file data * @param options the GridFSUploadOptions * @return a publisher with a single element, representing when the successful upload of the source. */ Publisher<Success> uploadFromStream(BsonValue id, String filename, AsyncInputStream source, GridFSUploadOptions options);
/** * Uploads the contents of the given {@code AsyncInputStream} to a GridFS bucket. * <p> * Reads the contents of the user file from the {@code source} and uploads it as chunks in the chunks collection. After all the * chunks have been uploaded, it creates a files collection document for {@code filename} in the files collection. * </p> * * @param clientSession the client session with which to associate this operation * @param filename the filename for the stream * @param source the Stream providing the file data * @param options the GridFSUploadOptions * @return a publisher with a single element, the ObjectId of the uploaded file. * @mongodb.server.release 3.6 * @since 1.7 */ Publisher<ObjectId> uploadFromStream(ClientSession clientSession, String filename, AsyncInputStream source, GridFSUploadOptions options);
/** * Uploads the contents of the given {@code AsyncInputStream} to a GridFS bucket. * <p> * Reads the contents of the user file from the {@code source} and uploads it as chunks in the chunks collection. After all the * chunks have been uploaded, it creates a files collection document for {@code filename} in the files collection. * </p> * * @param clientSession the client session with which to associate this operation * @param id the custom id value of the file * @param filename the filename for the stream * @param source the Stream providing the file data * @param options the GridFSUploadOptions * @return a publisher with a single element, representing when the successful upload of the source. * @mongodb.server.release 3.6 * @since 1.7 */ Publisher<Success> uploadFromStream(ClientSession clientSession, BsonValue id, String filename, AsyncInputStream source, GridFSUploadOptions options);