Skip to content

Allow adding media_type to from_* class methods flor blobs. #352

@julianstirling

Description

@julianstirling

Is your feature request related to a problem? Please describe.

If I have a camera that can capture in multiple formats then to follow the current instructions in the docs I would need to create a class for each format just to set the media_type string. Then a function either for each type of image with a specific return, or a large switch statement to decide what class to create.

I can create a blob directly with from_bytes, from_file, from_temporary_directory. Then once it is created change the media type property.

Describe the solution you'd like

Add an optional argument to set the "media_type" to the from_* class methods so I can go:

MEDIA_TYPES = {
    ".jpg": "image/jpeg",
    ".jpeg": "image/jpeg",
    ".png": "image/png",
    ".tiff": "image/tiff",
}

...

@lt.action
def image_as_blob(self):
    filepath = self.capture_to_disk()
    ext = os.path.splitext(filepath)[1]
    media_type = MEDIA_TYPES[ext]
    return lt.blob.Blob.from_file(filepath, media_type=media_type)

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions