Skip to content

Commit

Permalink
Added PostAttendeeImage HTTP method.
Browse files Browse the repository at this point in the history
  • Loading branch information
kalrit718 committed Apr 28, 2022
1 parent 5204ad2 commit 70a518b
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 3 deletions.
Binary file modified .vs/ProjectMOFI_Server_WebAPI/v17/.suo
Binary file not shown.
33 changes: 31 additions & 2 deletions Controllers/AttendeeController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Blob;
using ProjectMOFI_Server_WebAPI.Models;
using ProjectMOFI_Server_WebAPI.MongoDB;

Expand All @@ -11,10 +13,14 @@ public class AttendeeController : ControllerBase {
private readonly IConfiguration _config;
MongoConnection _connection;

private string blobConnectionString;

public AttendeeController(IWebHostEnvironment env, IConfiguration config) {
_config = config;
_webHostEnvironment = env;
_connection = new MongoConnection(config);

blobConnectionString = _config["BlobDetails-ConnectionString"];
}

[HttpGet]
Expand Down Expand Up @@ -62,8 +68,32 @@ public async Task<IActionResult> GetImagePathOfAttendee(string id) {
}
}

[HttpPost("UploadAttendeeImage")]
public async Task<IActionResult> PostAttendee(AttendeeImage attendeeImage) {
try {
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobConnectionString);
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("mofi-user-images");

string newFileName = attendeeImage.AttendeeId + "_UserImage.jpg";
var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(newFileName);
cloudBlockBlob.Properties.ContentType = "image/jpeg";

using (var stream = new MemoryStream(Convert.FromBase64String(attendeeImage.Base64String))) {
await cloudBlockBlob.UploadFromStreamAsync(stream);
}

string imageUploadedPath = "https://mofiblob.blob.core.windows.net/mofi-user-images/" + attendeeImage.AttendeeId + "_UserImage.jpg";
return await Task.FromResult(Created("", imageUploadedPath));
}
catch (Exception ex) {
Console.WriteLine(ex.StackTrace);
return StatusCode(500, "[ERROR]- An unexpected error occured!");
}
}

[HttpPost]
public async Task<IActionResult> PostAttendee(Attendee newAttendee) {
public async Task<IActionResult> PostAttendeeImage(Attendee newAttendee) {
try {
_connection.InsertUser(newAttendee);
return await Task.FromResult(Created("", newAttendee));
Expand All @@ -73,7 +103,6 @@ public async Task<IActionResult> PostAttendee(Attendee newAttendee) {
return StatusCode(500, "[ERROR]- An unexpected error occured!");
}
}


}
}
6 changes: 6 additions & 0 deletions Models/AttendeeImage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ProjectMOFI_Server_WebAPI.Models {
public class AttendeeImage {
public string AttendeeId { get; init; }
public string Base64String { get; init; }
}
}
Binary file modified bin/Debug/net6.0/ProjectMOFI_Server_WebAPI.dll
Binary file not shown.
Binary file modified bin/Debug/net6.0/ProjectMOFI_Server_WebAPI.pdb
Binary file not shown.
Binary file modified bin/Debug/net6.0/ref/ProjectMOFI_Server_WebAPI.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
68d8c9f984211b5a83e2114dd30c3e582fbcbf44
9b65bbac4a900cb46aa66323d3a902ad99ed7014
Binary file modified obj/Debug/net6.0/ProjectMOFI_Server_WebAPI.dll
Binary file not shown.
Binary file modified obj/Debug/net6.0/ProjectMOFI_Server_WebAPI.pdb
Binary file not shown.
Binary file modified obj/Debug/net6.0/ref/ProjectMOFI_Server_WebAPI.dll
Binary file not shown.
3 changes: 3 additions & 0 deletions obj/staticwebassets.pack.sentinel
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,6 @@
2.0
2.0
2.0
2.0
2.0
2.0

0 comments on commit 70a518b

Please sign in to comment.