// GET api/getsasurl public string Get() { var fileName = "lg/" +Guid.NewGuid() + ".temp"; var cs = new ContosoStorage(); var result = cs.GetSasUrlAndSetCORS(AppSettings.UploadContainerName, fileName); return result ; }
public Image AddImageToDB(string AlbumId, string UserId, string containerName, string fileName, string UploadFormat) { ContosoStorage cs = new ContosoStorage(); var ctx = new MobileServiceContext(); var img = new Image { Album = ctx.Albums.Where(x => x.Id == AlbumId).FirstOrDefault(), User = ctx.Users.Where(x => x.Id == UserId).FirstOrDefault(), Id = Guid.NewGuid().ToString(), UploadFormat = UploadFormat, ContainerName = AppSettings.StorageWebUri + containerName, FileName = fileName, }; ctx.Images.Add(img); try { ctx.SaveChanges(); return img; } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }
public async Task<CommitBlobResponse> Post([FromBody]CommitBlobRequest commitBlobRequest) { var res = new CommitBlobResponse(); var cs = new ContosoStorage(); string fileExt = BlobInformation.DEFAULT_FILE_EXT; //if (!commitBlobRequest.IsMobile) //{ fileExt = cs.CommitUpload(commitBlobRequest); //} var url = commitBlobRequest.SasUrl.Replace(AppSettings.StorageWebUri, ""); var urldata = url.Split('?'); var index = urldata[0].IndexOf('/'); var content = urldata[0].Split('/'); var containerName = urldata[0].Substring(0, index); // var fileName = urldata[0].Replace(containerName + "/", ""); string fileGuidName = urldata[0].Replace(containerName + "/lg/", "").Replace(".temp", ""); var ibl = new ImageBusinessLogic(); var image = ibl.AddImageToDB(commitBlobRequest.AlbumId, commitBlobRequest.UserId, containerName, fileGuidName + "." + fileExt, commitBlobRequest.IsMobile); if (image != null) { res.Success = true; res.ImageId = image.Id; } var qm = new QueueManager(); var blobInfo = new BlobInformation(fileExt); blobInfo.BlobUri = cs.GetBlobUri(containerName, urldata[0].Replace(containerName, "")); // blobInfo.FileGuidName = fileGuidName; blobInfo.ImageId = fileGuidName; await qm.PushToResizeQueue(blobInfo); return res; }