in Application/UI/mvc-frontend/ImageRecognition/ImageRecognitionManager.cs [38:79]
public async Task<Photo> AddPhoto(string albumId, string userId, string name, Stream stream)
{
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);
using (var fileStream = File.OpenWrite(tempFile))
{
Utilities.CopyStream(stream, fileStream);
}
var putRequest = new PutObjectRequest
{
BucketName = _appOptions.PhotoStorageBucket,
Key = $"private/uploads/{userId}/{photoId}",
FilePath = tempFile
};
await _s3Client.PutObjectAsync(putRequest).ConfigureAwait(false);
return photo;
}
finally
{
if (File.Exists(tempFile)) File.Delete(tempFile);
}
}