Skip to content

Blob endpoint fails to store Excel/Fails to determine encoding #156

@krowvin

Description

@krowvin

When working on storing an excel file:

i.e.
https://cwms-data.usace.army.mil/cwms-data/blobs/24HOURDATA.XLSX?office=SWT

I was running into an issue where if I attempted to store raw bytes and have it encode this it would fail to determine the encoding.
I.e.

Attempts to check if it is already base64 encoded for backwards compat

then this part encodes it for a comparison

But if you encode something that is not encoded already it will result in a failed check.

I'm not sure how to better check the encoding

But perhaps at a minimum we could check if bytes vs string are sent in:
I.e.

    value = data["value"]
    if isinstance(value, bytes):
        data["value"] = base64.b64encode(value).decode("utf-8")
    elif isinstance(value, str):
        data["value"] = base64.b64encode(value.encode("utf-8")).decode("utf-8")
    else:
        raise TypeError("Blob 'value' must be bytes or string")

then within the string check to see if it's already a base64 encoded string (perhaps we can do this with headers instead of attempting a re-encode?)

Wanted to discuss options before I submitted a PR to fix!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions