/// <summary> /// Creates the stream. /// </summary> /// <param name="blobInfo">The BLOB info.</param> /// <returns></returns> public override Stream CreateStream(BlobInfo blobInfo) { if (this.GetInfo(blobInfo.Uid) != null) { throw new Exception("Stream with such Guid already exist."); } Stream stream = null; try { BlobStorage.RaiseCreatingEvent(blobInfo); AddObjectRequest request = new AddObjectRequest(_Service, this.BucketName, blobInfo.Uid.ToString()); request.ContentLength = blobInfo.ContentSize; request.ContentType = blobInfo.ContentType; request.ContentDisposition = String.Format("filename={0}", blobInfo.FileName); request.Metadata["FileName"] = blobInfo.FileName; stream = request.GetRequestStream(); BlobStorage.RaiseCreatedEvent(blobInfo); } catch (Exception exception) { Trace.WriteLine(exception); throw; } return(stream); }
protected void SendStream(AddObjectRequest addRequest, Stream fileStream) { addRequest.ContentLength = fileStream.Length; using (var outputStream = addRequest.GetRequestStream()) { fileStream.CopyTo(outputStream); } Send(addRequest); }