-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Description
Description
The current implementation of image replacement in WordDocumentGenerator.cs
only supports downloading images from HTTP/HTTPS URLs using HttpClient. This limits the functionality when users want to use local image files.
Current Behavior
The ReplaceImagePlaceholders
method currently only handles HTTP URLs:
// Asynchronously download image data using HttpClient
byte[] imageData = await _httpClient.GetByteArrayAsync(imagePath);
Proposed Enhancement
Modify the code to detect whether the image path is:
- An HTTP/HTTPS URL - continue using HttpClient
- A local file path - use File.ReadAllBytesAsync() instead
Suggested Implementation
byte[] imageData;
if (Uri.TryCreate(imagePath, UriKind.Absolute, out Uri? imageUri) &&
(imageUri.Scheme == Uri.UriSchemeHttp || imageUri.Scheme == Uri.UriSchemeHttps))
{
// Download from HTTP/HTTPS URL
imageData = await _httpClient.GetByteArrayAsync(imagePath);
}
else
{
// Read from local file
imageData = await File.ReadAllBytesAsync(imagePath);
}
Benefits
- Increased flexibility for users who want to use local images
- Better support for various deployment scenarios
- Maintains backward compatibility with existing HTTP URL usage
References
Metadata
Metadata
Assignees
Labels
No labels