Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New ImagePart media added with extension .bin #1488

Closed
psyvision opened this issue Jul 6, 2023 · 4 comments · Fixed by #1498
Closed

New ImagePart media added with extension .bin #1488

psyvision opened this issue Jul 6, 2023 · 4 comments · Fixed by #1498
Assignees
Milestone

Comments

@psyvision
Copy link

Describe the bug

This is a follow up to an original bug #1305 "New ImagePart is created as .bin instead of real extension" which is still an issue with the most recent 2.20.0 release.

When adding a new ImagePart the media in the bundled package has an extension of .bin instead of .jpg etc.

Screenshots
If applicable, add screenshots to help explain your problem.

To Reproduce

Create a new document and add an ImagePart using the following code:

// Load an image and get the appropriate mime type
var image = System.Drawing.Image.LoadFromFile("myphoto.jpg");
var codes = ImageCodecInfo.GetImageDecoders();
var mimeType = codes.First(c => c.FormatID == image.RawFormat.Guid).MimeType;

var imagePart = mainPart.AddImagePart(mimeType); // image/jpeg

using var stream = new MemoryStream();
image.Save(stream, image.RawFormat);
stream.Position = 0;
imagePart.FeedData(stream);

Observed behavior
The media is added to the word document package with .bin extension

Expected behavior
The media is added to the word document package with .jpg extension

Desktop (please complete the following information):

  • OS: Windows 10
  • Office version: 2306 - 16529.20154
  • .NET Target: .NET Core 6
  • DocumentFormat.OpenXml Version: 2.20.0
@twsouthwick
Copy link
Member

@tomjebo can the fix you did for this on the v3 release be back ported?

@mikeebowen
Copy link
Collaborator

@psyvision , The next release of v3.0.0 beta will have a fix for this issue and your code will work as is. A future release of v2.20.1 will also fix this issue, but the syntax will need to change to ImagePartExtensions.AddImagePart(doc.MainDocumentPart, mimeType);

mikeebowen added a commit that referenced this issue Jul 28, 2023
@psyvision
Copy link
Author

@psyvision , The next release of v3.0.0 beta will have a fix for this issue and your code will work as is. A future release of v2.20.1 will also fix this issue, but the syntax will need to change to ImagePartExtensions.AddImagePart(doc.MainDocumentPart, mimeType);

Thank you! Looking forward to the releases :)

@mikeebowen
Copy link
Collaborator

Hi @psyvision just an FYI,
The current 3.0.0-beta3 release contains the fix for this. If you can switch to 3.0.0 that would be your best option. I'm not sure when / if we'll get to the 2.20.1 release, but if you need to stay on v2, you can view the fix here if you want to add it to your own fork: https://github.com/dotnet/Open-XML-SDK/pull/1492/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants