/// <summary> /// Initializes a new instance of the <see cref="GridFSBucketOptions"/> class. /// </summary> /// <param name="other">The other <see cref="GridFSBucketOptions"/> from which to copy the values.</param> public GridFSBucketOptions(GridFSBucketOptions other) { _bucketName = other.BucketName; _chunkSizeBytes = other.ChunkSizeBytes; _readPreference = other.ReadPreference; _writeConcern = other.WriteConcern; }
/// <summary> /// Initializes a new instance of the <see cref="GridFSBucketOptions"/> class. /// </summary> /// <param name="other">The other <see cref="GridFSBucketOptions.Immutable"/> from which to copy the values.</param> public GridFSBucketOptions(GridFSBucketOptions.Immutable other) { _bucketName = other.BucketName; _chunkSizeBytes = other.ChunkSizeBytes; _readPreference = other.ReadPreference; _writeConcern = other.WriteConcern; }
public async Task<ActionResult> EditPhoto(HttpPostedFileBase profilePhotoUser, string usernamePhoto) { if (profilePhotoUser != null) { if (profilePhotoUser.ContentLength > 0) { GridFSBucketOptions bucketOptions = new GridFSBucketOptions() { BucketName = "ProfileImages" }; var fs = new GridFSBucket(KonradRequirementsDatabase, bucketOptions); // getting filename string fileName = Path.GetFileName(profilePhotoUser.FileName); //get the bytes from the content stream of the file byte[] pictureBytes = new byte[profilePhotoUser.ContentLength]; using (BinaryReader theReader = new BinaryReader(profilePhotoUser.InputStream)) { pictureBytes = theReader.ReadBytes(profilePhotoUser.ContentLength); } // Saving picture var objectId = await fs.UploadFromBytesAsync(fileName, pictureBytes); var filter = Builders<BsonDocument>.Filter.Eq("Username", usernamePhoto); var update = Builders<BsonDocument>.Update .Set("ProfileImageName", fileName); var result = await usersCollection.UpdateOneAsync(filter, update); return RedirectToAction("MyProfile", new { ReLogin = true, result = result }); } } return null; }
// constructors /// <summary> /// Initializes a new instance of the <see cref="GridFSBucket" /> class. /// </summary> /// <param name="database">The database.</param> /// <param name="options">The options.</param> public GridFSBucket(IMongoDatabase database, GridFSBucketOptions options = null) { _database = Ensure.IsNotNull(database, nameof(database)); _options = options == null ? ImmutableGridFSBucketOptions.Defaults : new ImmutableGridFSBucketOptions(options); _cluster = database.Client.Cluster; _ensuredIndexes = 0; }
// constructors /// <summary> /// Initializes a new instance of the <see cref="GridFSBucket" /> class. /// </summary> /// <param name="database">The database.</param> /// <param name="options">The options.</param> public GridFSBucket(IMongoDatabase database, GridFSBucketOptions options = null) { _database = Ensure.IsNotNull(database, nameof(database)); _options = options == null ? ImmutableGridFSBucketOptions.Defaults : new ImmutableGridFSBucketOptions(options); _cluster = database.Client.Cluster; _ensuredIndexes = 0; }
// constructors /// <inheritdoc /> public GridFSBucket(IMongoDatabase database, GridFSBucketOptions.Immutable options = null) { _database = Ensure.IsNotNull(database, "database"); _options = options ?? GridFSBucketOptions.Immutable.Defaults; _cluster = database.Client.Cluster; _ensuredIndexes = 0; }
/// <summary> /// Initializes a new instance of the <see cref="GridFSBucketOptions"/> class. /// </summary> /// <param name="other">The other <see cref="GridFSBucketOptions"/> from which to copy the values.</param> public GridFSBucketOptions(GridFSBucketOptions other) { Ensure.IsNotNull(other, nameof(other)); _bucketName = other.BucketName; _chunkSizeBytes = other.ChunkSizeBytes; _readPreference = other.ReadPreference; _writeConcern = other.WriteConcern; }
/// <summary> /// Initializes a new instance of the <see cref="GridFSBucketOptions"/> class. /// </summary> /// <param name="other">The other <see cref="GridFSBucketOptions"/> from which to copy the values.</param> public GridFSBucketOptions(GridFSBucketOptions other) { Ensure.IsNotNull(other, nameof(other)); _bucketName = other.BucketName; _chunkSizeBytes = other.ChunkSizeBytes; _readConcern = other.ReadConcern; _readPreference = other.ReadPreference; _writeConcern = other.WriteConcern; }
/// <summary> /// Initializes a new instance of the <see cref="ImmutableGridFSBucketOptions" /> class. /// </summary> /// <param name="other">The other <see cref="GridFSBucketOptions"/> from which to copy the values.</param> public ImmutableGridFSBucketOptions(GridFSBucketOptions other) { Ensure.IsNotNull(other, nameof(other)); _bucketName = other.BucketName; _chunkSizeBytes = other.ChunkSizeBytes; _readConcern = other.ReadConcern; _readPreference = other.ReadPreference; _writeConcern = other.WriteConcern; _suppressEnsureIndexes = other.SuppressEnsureIndexes; }
// constructors /// <summary> /// Initializes a new instance of the <see cref="GridFSBucket" /> class. /// </summary> /// <param name="database">The database.</param> /// <param name="options">The options.</param> public GridFSBucket(IMongoDatabase database, GridFSBucketOptions options = null) { _database = Ensure.IsNotNull(database, nameof(database)); _options = options == null ? ImmutableGridFSBucketOptions.Defaults : new ImmutableGridFSBucketOptions(options); _cluster = database.Client.Cluster; var idSerializer = _options.SerializerRegistry.GetSerializer <TFileId>(); _idSerializationInfo = new BsonSerializationInfo("_id", idSerializer, typeof(TFileId)); _fileInfoSerializer = new GridFSFileInfoSerializer <TFileId>(idSerializer); }
// constructors /// <summary> /// Initializes a new instance of the <see cref="GridFSBucket" /> class. /// </summary> /// <param name="database">The database.</param> /// <param name="options">The options.</param> public GridFSBucket(IMongoDatabase database, GridFSBucketOptions options = null) : base(database, options) { _bsonValueBucket = new GridFSBucket <BsonValue>(database, options); }
private async Task<FileContentResult> GetProfileService(string fileName) { GridFSBucketOptions bucketOptions = new GridFSBucketOptions() { BucketName = "ProfileImages" }; var fs = new GridFSBucket(KonradRequirementsDatabase, bucketOptions); var t = fs.DownloadAsBytesByNameAsync(fileName); Task.WaitAll(t); byte[] image = t.Result; return File(image, "image/jpg"); }