Added an API to get persigned url for provided document
This commit is contained in:
parent
afdf51eae3
commit
85911c4536
@ -272,5 +272,44 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
return Ok(ApiResponse<object>.SuccessResponse(response, "Images for provided batchId fetched successfully", 200));
|
return Ok(ApiResponse<object>.SuccessResponse(response, "Images for provided batchId fetched successfully", 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("{documentId}")]
|
||||||
|
public async Task<IActionResult> GetImage(Guid documentId)
|
||||||
|
{
|
||||||
|
// Log the start of the image fetch process
|
||||||
|
_logger.LogInfo("GetImage called for DocumentId: {DocumentId}", documentId);
|
||||||
|
|
||||||
|
// Step 1: Get the currently logged-in employee (for future use like permission checks or auditing)
|
||||||
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
|
||||||
|
// Step 2: Fetch the document from the database based on the provided ID
|
||||||
|
var document = await _context.Documents.FirstOrDefaultAsync(d => d.Id == documentId);
|
||||||
|
|
||||||
|
// Step 3: If document doesn't exist, return a 400 Bad Request response
|
||||||
|
if (document == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Document not found for DocumentId: {DocumentId}", documentId);
|
||||||
|
return BadRequest(ApiResponse<object>.ErrorResponse("Document not found", "Document not found", 400));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 4: Generate pre-signed URLs for thumbnail and full image (if keys exist)
|
||||||
|
string? thumbnailUrl = document.ThumbS3Key != null
|
||||||
|
? _s3Service.GeneratePreSignedUrlAsync(document.ThumbS3Key)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
string? imageUrl = document.S3Key != null
|
||||||
|
? _s3Service.GeneratePreSignedUrlAsync(document.S3Key)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
// Step 5: Prepare the response object
|
||||||
|
var response = new
|
||||||
|
{
|
||||||
|
ThumbnailUrl = thumbnailUrl,
|
||||||
|
ImageUrl = imageUrl
|
||||||
|
};
|
||||||
|
|
||||||
|
// Step 6: Log successful fetch and return the result
|
||||||
|
_logger.LogInfo("Image fetched successfully for DocumentId: {DocumentId}", documentId);
|
||||||
|
return Ok(ApiResponse<object>.SuccessResponse(response, "Image fetched successfully", 200));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user