public ActionResult Upload(string contentName) { { CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("contentcontainer"); if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { CloudBlockBlob blockBlob = container.GetBlockBlobReference(file.FileName); blockBlob.UploadFromStream(file.InputStream); BlobContent bcontent = new BlobContent { Name = contentName, URL = blockBlob.Uri.ToString(), ContainerName = container.Name, CreateDate = DateTime.Now, FileName = blockBlob.Name }; db.BlobContents.Add(bcontent); db.SaveChanges(); } } } return(RedirectToAction("Index")); }
public async Task <IActionResult> ReadBlobContentAsync(long blobId, [FromQuery(Name = "path")] string path) { BlobContent blobContent = await _storageService.ReadBlobContentAsync(TenantId, blobId, path); if (blobContent == null) { return(NotFound()); } return(File(blobContent.Stream, blobContent.Type, blobContent.Name)); }
public async Task <IActionResult> ReadUserImageAsync(long userId, UserImageType userImageType) { BlobContent blobContent = await _userService.ReadUserImageAsync(TenantId, userId, userImageType); if (blobContent == null) { return(NotFound()); } return(File(blobContent.Stream, blobContent.Type, blobContent.Name)); }
public async Task <IActionResult> ReadBlobContent(long tenantId, long blobId) { BlobContent blobContent = await _storageService.ReadBlobContentAsync(tenantId, blobId); if (blobContent == null) { return(NotFound()); } return(File(blobContent.Stream, blobContent.Type)); }
public async Task <IActionResult> ReadAlbumElementBlobContentAsync(long elementId, long blobSetId, [FromQuery] string blobLabel) { BlobContent content = await _albumElementService.ReadBlobContentAsync(TenantId, elementId, blobSetId, blobLabel); if (content == null) { return(NotFound()); } return(File(content.Stream, content.Type, content.Name)); }
public async Task <IActionResult> ReadPageImageAsync(long pageId, PageImageType pageImageType) { BlobContent blobContent = await _pageService.ReadPageImageAsync(TenantId, pageId, pageImageType); if (blobContent == null) { return(NotFound()); } return(File(blobContent.Stream, blobContent.Type, blobContent.Name)); }
public ActionResult DeleteConfirmed(int id) { BlobContent blob = db.BlobContents.Find(id); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("contentcontainer"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(blob.FileName); blockBlob.DeleteIfExists(); db.BlobContents.Remove(blob); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BlobContent blob = db.BlobContents.Find(id); if (blob == null) { return(HttpNotFound()); } return(View(blob)); }
public async Task <IActionResult> CreateImageAsync(IFormCollection files, string modes, string sizes) { try { if (modes == null || sizes == null) { return(BadRequest()); } string[] modeArray = modes.Split(','); string[] sizeArray = sizes.Split(','); if (modeArray.Length != sizeArray.Length) { return(BadRequest()); } IEnumerable <ResizeMode> resizeModes = modeArray.Select(m => GetResizeMode(m)); IEnumerable <ImageSize> imageSizes = sizeArray.Select(s => new ImageSize(s)); List <ResizeOptions> options = new List <ResizeOptions>(); foreach (ResizeMode resizeMode in resizeModes) { options.Add(new ResizeOptions { Mode = resizeMode }); } int index = 0; foreach (ImageSize imageSize in imageSizes) { options[index].Width = imageSize.Width; options[index].Height = imageSize.Height; index++; } List <ImageResizeUploadResult> uploadResults = new List <ImageResizeUploadResult>(); foreach (IFormFile file in files.Files) { using (Stream stream = file.OpenReadStream()) { IBlobContent content = new BlobContent { Name = Path.GetFileName(file.FileName), Type = file.ContentType, Stream = stream }; uploadResults.Add(await _storageService.CreateImageAsync(TenantId, content, options)); } } return(Ok(uploadResults)); } catch (ValidationErrorException ex) { return(BadRequest(new { errors = ex.Errors })); } }
private async Task LoadAsync(Guid?id = null) { switch (_parentType) { case ParentType.Space: { BlobContentTypeList = await DigitalTwinsHelper.GetTypesAsync( Models.Types.SpaceBlobType, _cache, Loggers.SilentLogger, onlyEnabled : true); BlobContentSubTypeList = await DigitalTwinsHelper.GetTypesAsync( Models.Types.SpaceBlobSubtype, _cache, Loggers.SilentLogger, onlyEnabled : true); break; } case ParentType.Device: { BlobContentTypeList = await DigitalTwinsHelper.GetTypesAsync( Models.Types.DeviceBlobType, _cache, Loggers.SilentLogger, onlyEnabled : true); BlobContentSubTypeList = await DigitalTwinsHelper.GetTypesAsync( Models.Types.DeviceBlobSubtype, _cache, Loggers.SilentLogger, onlyEnabled : true); break; } case ParentType.Sensor: { BlobContentTypeList = await DigitalTwinsHelper.GetTypesAsync( Models.Types.SensorDataType, _cache, Loggers.SilentLogger, onlyEnabled : true); BlobContentSubTypeList = await DigitalTwinsHelper.GetTypesAsync( Models.Types.DeviceBlobSubtype, _cache, Loggers.SilentLogger, onlyEnabled : true); break; } } if (id != null) { this.SelectedBlobContentItem = await DigitalTwinsHelper.GetBlobAsync((Guid)id, _cache, Loggers.SilentLogger, true); } else { SelectedBlobContentItem = new BlobContent(); } this.SelectedBlobContentItem.ParentType = _parentType; }
public GatewayBlob(object blob, BlobContent blobContent) { this.Blob = blob; this.blobContent = blobContent; switch (blobContent) { case BlobContent.Binary: this.BlobSize = ((byte[])blob).Length; break; case BlobContent.Ansi: this.BlobSize = ((string)blob).Length; break; case BlobContent.Unicode: this.BlobSize = ((string)blob).Length * 2; break; } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); string connString = ConfigurationManager.AppSettings["BlobStorageConnectionString"]; BlobTable <Parameter> .Initialize(connString); BlobTable <Account> .Initialize(connString); BlobTable <SmartDevice> .Initialize(connString); BlobTable <Setting> .Initialize(connString); BlobTable <UserGroup> .Initialize(connString); BlobTable <User> .Initialize(connString); BlobTable <Alarm> .Initialize(connString); BlobContent.Initialize(connString, this); string pushConnString = ConfigurationManager.AppSettings["PushHubConnectionString"]; string hubname = ConfigurationManager.AppSettings["PushHubName"]; PushManager.Start(hubname, pushConnString); //SmartMonitorDataManager<Parameter>.Initialize("Parameters"); //SmartMonitorDataManager<Account>.Initialize("Account"); //SmartMonitorDataManager<SmartDevice>.Initialize("SmartDevices"); //SmartMonitorDataManager<Setting>.Initialize("Settings"); //SmartMonitorDataManager<UserGroup>.Initialize("UserGroups"); //SmartMonitorDataManager<User>.Initialize("Users"); //PushNotificationManager.Instance.Initialize(); //AzureActiveDirectoryManager.Instance.Initialize(); //IoTHubEventManager.Instance.Initialize(); }
public ActionResult Save() { foreach (string name in Request.Files) { var file = Request.Files[name]; string fileName = System.IO.Path.GetFileName(file.FileName); BlobContent.UploadImage(containerName, fileName); //string imagename = file.FileName; //int index = imagename.IndexOf('.'); //imagename = (index > 0) ? imagename.Substring(0, index) : imagename; //imagename = imagename.Replace(' ', '_'); //Image image = new Image(imagename, fileName, Request["description"]); //ImageDataManager.Add(image, file); } return(HttpNotFound()); }
public static async Task <bool> UpdateBlobAsync(HttpClient httpClient, ILogger logger, ParentType blobType, BlobContent blobContent, IFormFile file) { var metadataContent = new StringContent(JsonConvert.SerializeObject(blobContent.ToCreate()), Encoding.UTF8, "application/json"); metadataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); var reader = new StreamReader(file.OpenReadStream()); var subContent = new StreamContent(reader.BaseStream); subContent.Headers.ContentType = MediaTypeHeaderValue.Parse(file.ContentType); var multipartContent = new MultipartFormDataContent("blobBoundary") { { metadataContent, "metadata" }, { subContent, "blob" } }; var response = await httpClient.PatchAsync($"{blobType}s/blobs/{blobContent.Id}", multipartContent); return(await IsSuccessCall(response, logger)); }
public async Task <IActionResult> ReadElementBlobAsync(Guid elementTypeId, long elementId, long blobSetId, string blobLabel) { BlobContent blobContent = await _elementServiceFactory.GetElementBlobContentAsync(TenantId, elementTypeId, elementId, blobSetId, blobLabel); return(File(blobContent.Stream, blobContent.Type, blobContent.Name)); }
public static async Task <Guid> CreateBlobAsync(HttpClient httpClient, ILogger logger, ParentType blobType, BlobContent blobContent, IFormFile file) { var metadataContent = new StringContent(JsonConvert.SerializeObject(blobContent.ToCreate()), Encoding.UTF8, "application/json"); metadataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); var reader = new StreamReader(file.OpenReadStream()); var subContent = new StreamContent(reader.BaseStream); subContent.Headers.ContentType = MediaTypeHeaderValue.Parse(file.ContentType); var multipartContent = new MultipartFormDataContent("blobBoundary") { { metadataContent, "metadata" }, { subContent, "blob" } }; var response = await httpClient.PostAsync($"{blobType}s/blobs", multipartContent); var id = await GetIdFromResponse(response, logger, multipartContent.ToString()); if (id != Guid.Empty) { await FeedbackHelper.Channel.SendMessageAsync($"{blobType} blob successfully created with the ID {id}", MessageType.Info); } return(id); }
// GET: Image public ActionResult Index() { return(View(BlobContent.ListImages(containerName))); }