Skip to content

cannot save image  #83

Closed as not planned
Closed as not planned
@Pengchengistaken

Description

@Pengchengistaken

code:

elif msg.type() == MessageType.MESSAGE_TYPE_IMAGE:
            img = await msg.to_file_box()
            # save the image as local file
            await img.to_file(f'./{img.name}')
            # send image file to the room
            if room:
                await room.say(img)

error log:

Wechaty - ERROR - internal error <('unknown file_box json object %s', '{"metadata": {}, "name": "message-2461588911633991485-image-normal.jpg", "size": 74127, "type": 7, "uuid": "9af52d2a-79b8-44b7-9728-e741c8e8a95c", "boxType": 7}')>

log source code:

# original box_type field name is boxType
        if 'boxType' not in json_obj:
            raise Exception('box field must be required')
        # assert that boxType value must match the value of FileBoxType values

        if json_obj['boxType'] == FileBoxType.Base64.value:
            file_box = FileBox.from_base64(
                base64=json_obj['base64'],
                name=json_obj['name']
            )
        elif json_obj['boxType'] == FileBoxType.Url.value:
            file_box = FileBox.from_url(
                url=json_obj['remoteUrl'],
                name=json_obj['name']
            )
        elif json_obj['boxType'] == FileBoxType.QRCode.value:
            file_box = FileBox.from_qr_code(
                qr_code=json_obj['qrCode']
            )
        else:
            raise ValueError('unknown file_box json object %s',
                             json.dumps(json_obj))

root cause:
The boxType of image is 7, but there is not such value in FileBoxType

lass FileBoxType(Enum):
    """
    option config for file box
    """
    Unknown = 0

    # Serializable by toJSON()

    Base64 = 1
    Url = 2
    QRCode = 3

    # Not serializable by toJSON()
    # Need to convert to FileBoxType.Base64 before call toJSON()
    Buffer = 4
    File = 5
    Stream = 6

Metadata

Metadata

Assignees

No one assigned

    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