public void Save() { string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(this); Stream stream = GenerateStreamFromString(jsonData); AwsS3.UploadFileToS3(stream, "Files/" + this.AuthorizationToken.ToString() + ".json"); }
public async Task <IActionResult> PutAwsS3([FromRoute] long id, [FromBody] AwsS3 awsS3) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != awsS3.Id) { return(BadRequest()); } _context.Entry(awsS3).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AwsS3Exists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static void Delete(string AuthorizationToken) { if (AwsS3.S3FileIsExists("Files/" + AuthorizationToken + ".json")) { AwsS3.DeleteImageToAws("Files/" + AuthorizationToken + ".json"); } }
public static void Log(string ordnum, string token, string data, string type) { string jsonData = data; Stream stream = GenerateStreamFromString(jsonData); AwsS3.UploadFileToS3(stream, "Logs/" + token + ".json"); }
public async Task <IActionResult> PostAwsS3([FromBody] dynamic data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Parse Data Newtonsoft.Json.Linq.JToken[] dataArray = ((Newtonsoft.Json.Linq.JContainer)data).ToArray(); string imageData = dataArray[0].First.ToString(); string unquieID = dataArray[1].First.ToString(); string name = dataArray[2].First.ToString(); string link = S3Items.uploadS3Object(imageData, unquieID); if (link != null) { AwsS3 awsS3 = new AwsS3() { UniqueCode = unquieID, Name = name, Filename = "", EmailStatus = "Sent", UploadedDate = DateTime.Now.ToShortDateString(), ImageLink = link, ApprovalStatus = "Pending", ApprovalDecisionNotes = "" }; _context.AwsS3.Add(awsS3); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (AwsS3Exists(awsS3.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetAwsS3", new { id = awsS3.Id }, awsS3)); } return(BadRequest()); }
public async Task <Metadata> ReadMetadata() { if (!IsValidBucketName()) { return(null); } var s3 = new AwsS3(configuration[BUCKETNAME], awsOptions); var getMetadataStream = await s3.ReadObject(ImageMetadataFile); using var stringReader = new StreamReader(getMetadataStream); return(JsonSerializer.Deserialize <Metadata>(stringReader.ReadToEnd())); }
public static AuthorizationConfig Load(string AuthorizationToken) { if (AwsS3.S3FileIsExists("Files/" + AuthorizationToken + ".json")) { string json = AwsS3.GetS3File("Files/" + AuthorizationToken + ".json"); AuthorizationConfig output = Newtonsoft.Json.JsonConvert.DeserializeObject <AuthorizationConfig>(json); return(output); } else { return(null); } }
public async void UpdateMetadata(Metadata metadata) { if (!IsValidBucketName()) { return; } var metadataJson = JsonSerializer.Serialize(metadata); using var inputStream = new MemoryStream(2048); using var writer = new StreamWriter(inputStream); await writer.WriteAsync(metadataJson); await writer.FlushAsync(); var s3 = new AwsS3(configuration[BUCKETNAME], awsOptions); await s3.WriteObject(ImageMetadataFile, inputStream); }
public async Task <IEnumerable <Image> > GetImages() { if (!IsValidBucketName()) { return(null); } Console.WriteLine("Bucket Name: " + configuration[BUCKETNAME]); var s3 = new AwsS3(configuration[BUCKETNAME], awsOptions); var s3Objects = await s3.GetObjectsList(); if (s3Objects == null) { return(null); } var images = new List <Image>(); foreach (var s3Object in s3Objects) { if (s3Object.Key.EndsWith(".json")) { continue; } var tags = await s3.GetObjectTags(s3Object); images.Add(new Image { Name = s3Object.Key, Orientation = tags?.GetOrientation() ?? Orientation.Unknown, Category = tags?.GetImageCategory() ?? Category.Portfolio }); } return(images); }
public static string PDFtoImage(string pdfPath, string imagePath) { PdfDocument doc = new PdfDocument(); Stream S3Stream = AwsS3.GetS3ImageForInputStream(pdfPath); doc.LoadFromStream(S3Stream); Image bmp = doc.SaveAsImage(0); Image emf = doc.SaveAsImage(0, Spire.Pdf.Graphics.PdfImageType.Bitmap); Image zoomImg = new Bitmap((int)(emf.Size.Width * 2), (int)(emf.Size.Height * 2)); using (Graphics g = Graphics.FromImage(zoomImg)) { g.ScaleTransform(2.0f, 2.0f); g.DrawImage(emf, new Rectangle(new Point(0, 0), emf.Size), new Rectangle(new Point(0, 0), emf.Size), GraphicsUnit.Pixel); } //bmp.Save(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Files\PDF\convertToBmp.bmp"), ImageFormat.Bmp); //emf.Save(imagePath, ImageFormat.Png); //zoomImg.Save(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Files\PDF\convertToZoom.png"), ImageFormat.Png); //save image into S3 Bukets Stream stream = ToStream(emf, ImageFormat.Png); AwsS3.UploadFileToS3(stream, imagePath); return(string.Empty); }