public ImageTagResponse Upload() { ImageTagResponse responseModel = new ImageTagResponse(); try { var files = Request.Form.Files; if (files == null && files.Count <= 0) { return(null); } var extension = Path.GetExtension(files[0].FileName); var fileName = string.Format(@"{0}" + extension, Guid.NewGuid()); string mimeType = files[0].ContentType; byte[] fileBytes; using (var ms = new MemoryStream()) { files[0].CopyTo(ms); fileBytes = ms.ToArray(); } BlobStorageService objBlobService = new BlobStorageService(); Image image = new Image { Path = objBlobService.UploadFileToBlob(fileName, fileBytes, mimeType), Name = fileName, CreateDate = DateTime.Now, LastModified = DateTime.Now, ExternalKey = _externalKey }; string tagResult = objBlobService.GenerateTags(image.Path); image.Tags = tagResult; _context.ImageRepo.Add(image); _context.SaveChanges(); var resultId = image.ImageId; if (!string.IsNullOrWhiteSpace(tagResult)) { responseModel = JsonConvert.DeserializeObject <ImageTagResponse>(tagResult); } if (responseModel != null) { responseModel.ImageId = resultId; } } catch (Exception ex) { Logger.writelog(ex.Message); responseModel = null; } return(responseModel); }