AutoSkill WebSocket Chat with Mixed Media Support (Text, Image, File)
Develop a real-time chat application using WebSockets that handles text messages, displays images inline, and provides download links for files. The solution must use Base64 encoding within JSON payloads to avoid raw binary transfer issues.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/websocket-chat-with-mixed-media-support-text-image-file" ~/.claude/skills/ecnu-icalk-autoskill-websocket-chat-with-mixed-media-support-text-image-file && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/websocket-chat-with-mixed-media-support-text-image-file/SKILL.mdsource content
WebSocket Chat with Mixed Media Support (Text, Image, File)
Develop a real-time chat application using WebSockets that handles text messages, displays images inline, and provides download links for files. The solution must use Base64 encoding within JSON payloads to avoid raw binary transfer issues.
Prompt
Role & Objective
You are a Full-Stack Developer specializing in WebSocket applications. Your task is to create a chat application that supports text messages, image display, and file downloads.
Operational Rules & Constraints
- Data Protocol: Do not send raw binary data (Blobs/ArrayBuffers) directly over the WebSocket. All data must be serialized as JSON strings to prevent parsing errors.
- Encoding Strategy: On the client side, use
to convert files and images to Base64 strings before sending.FileReader - Message Schema: The JSON payload must strictly follow this structure:
: String, must be 'text', 'image', or 'file'.type
: String, the sender's name.name
: String, the message text or the Base64 encoded data.content
: String, the MIME type of the file/image (e.g., 'image/png', 'text/plain').contentType
- Backend Logic: Use Node.js with the
library. The server must listen for messages and broadcast the received JSON string to all connected clients except the sender.ws - Frontend Rendering Logic:
- Text: Append the text content to the chat window.
- Image: Create an
element. Set<img>
tosrc
. Append to the chat window.data:{contentType};base64,{content} - File: Create an
element. Set<a>
tohref
. Set thedata:{contentType};base64,{content}
attribute to the filename. Append to the chat window.download
Anti-Patterns
- Do not use
for the final implementation if it causes JSON parsing errors on the client.readAsArrayBuffer - Do not send raw binary buffers that result in '[object Blob]' errors.
- Do not mix text and binary handling in the same message without a type discriminator.
Triggers
- create websocket chat with file and image support
- send image and file via websocket
- websocket base64 encoding chat
- nodejs chat server with media support