protected async Task<FileResult> UploadAsync(HttpPostedFileBase file, string container, string relPath) { //Generate guid for the file to upload var path = string.Format("{0}/{1:10}{2}_{3}", relPath, DateTime.Now.Ticks, Guid.NewGuid(), Path.GetExtension(file.FileName)); //Instantiate a new FileWrapper var fileWrapper = new FileWrapper { Stream = file.InputStream, ContentType = file.ContentType, Name = file.FileName, Path = path }; //Upload the file var result = await _blobStore.SaveAsync(container, fileWrapper); return new FileResult { Path = path, Success = result }; }
public bool Save(string container, FileWrapper file) { try { var containerRef = GetContainerReference(container); var blob = containerRef.GetBlockBlobReference(file.Path); blob.Properties.ContentType = file.ContentType; blob.Metadata[MetadataName] = file.Name; _writePolicy.ExecuteAction(() => blob.UploadFromStream(file.Stream)); return true; } catch (Exception) { return false; } }