public ICentralizedFile AddUpdateFile(string path, string fileName, Stream contentStream) { using (new TracePoint($"[cfs] AddUpdate '{FileStoreKey}' '{path}' '{fileName}'")) { //Work around for https://community.telligent.com/community/f/1964/t/1141418 if (contentStream.Position != 0) { if (!contentStream.CanSeek) { throw new NotSupportedException("Stream is not at beginning, and cannot be seeked to the beginning"); } contentStream.Seek(0, SeekOrigin.Begin); } var blob = GetBlob(path, fileName); blob.Properties.ContentType = MimeTypes.GetMimeTypeByFileName(fileName); blob.UploadFromStream(contentStream, options: new BlobRequestOptions { ServerTimeout = TimeSpan.FromMinutes(5) }); return(new AzureBlobFileReference(blob, _fileStoreData)); } }
public ICentralizedFile AddUpdateFile(string path, string fileName, Stream contentStream) { using (new TracePoint($"[cfs] AddUpdate '{FileStoreKey}' '{path}' '{fileName}'")) { //Work around for https://community.telligent.com/community/f/1964/t/1141418 if (contentStream.Position != 0) { if (!contentStream.CanSeek) { throw new NotSupportedException("Stream is not at beginning, and cannot be seeked to the beginning"); } contentStream.Seek(0, SeekOrigin.Begin); } var blob = GetBlob(path, fileName); blob.Properties.ContentType = MimeTypes.GetMimeTypeByFileName(fileName); bool alreadyExists = blob.Exists(); if (alreadyExists) { EventExecutor.OnBeforeUpdate(ConvertBlobToCentralizedFile(blob)); } else { EventExecutor.OnBeforeCreate(FileStoreKey, path, fileName); } blob.UploadFromStream(contentStream, options: new BlobRequestOptions { ServerTimeout = TimeSpan.FromMinutes(5) }); var file = ConvertBlobToCentralizedFile(blob); if (alreadyExists) { EventExecutor.OnAfterUpdate(file); } else { EventExecutor.OnAfterCreate(file); } return(file); } }