Skip to content

fileType option changes MIME type but not file extension in output file name #233

Description

@HarshEvident
  1. Import and compress an image:

import imageCompression from "browser-image-compression";

`const options = {
maxSizeMB: 1,
fileType: "image/webp"
};

const compressedFile = await imageCompression(file, options);
console.log(compressedFile.type); // "image/webp"
console.log(compressedFile.name); // "example.jpg"`

The output compressedFile.type is correctly "image/webp".

The output compressedFile.name still has the original extension (e.g., example.jpg).

Expected Behavior:

The output file name should also have its extension updated to match the new file type, e.g., example.webp.

Actual Behavior:

MIME type is updated but extension remains from the original file.

Environment:

Package: browser-image-compression

Version: 2.0.2

Browser: [e.g., Chrome 139, Safari, etc.]

Suggestion / Possible Fix:
Update the logic to rename the file extension when fileType is specified, or add a new option to control whether the extension should be updated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions