in Application/API/ImageRecognition.API/Controllers/PhotoController.cs [89:133]
public async Task<IActionResult> AddPhoto([FromQuery] string albumId, [FromQuery] string name,
[FromQuery] string sourceImageUrl)
{
var userId = Utilities.GetUsername(HttpContext.User);
var tempFile = Path.GetTempFileName();
try
{
var photoId = name + "-" + Guid.NewGuid();
var photo = new Photo
{
AlbumId = albumId,
Bucket = _appOptions.PhotoStorageBucket,
CreatedDate = DateTime.UtcNow,
UpdatedDate = DateTime.UtcNow,
PhotoId = photoId,
Owner = userId,
ProcessingStatus = ProcessingStatus.Pending,
UploadTime = DateTime.UtcNow
};
await _ddbContext.SaveAsync(photo).ConfigureAwait(false);
await using (var fileStream = System.IO.File.OpenWrite(tempFile))
{
await Utilities.CopyStreamAsync(sourceImageUrl, fileStream);
}
var putRequest = new PutObjectRequest
{
BucketName = _appOptions.PhotoStorageBucket,
Key = $"private/uploads/{userId}/{photoId}",
FilePath = tempFile
};
await _s3Client.PutObjectAsync(putRequest).ConfigureAwait(false);
return Ok();
}
finally
{
if (System.IO.File.Exists(tempFile)) System.IO.File.Delete(tempFile);
}
}