Zalo Upload Attachment icon

Zalo Upload Attachment

Upload attachment (ảnh, video, file) lên Zalo sử dụng kết nối đăng nhập bằng cookie

Zalo Upload Attachment

AI-generated

Overview

This node uploads attachments such as images, videos, or other files to a Zalo chat thread, which can be either a user or a group. It supports uploading single or multiple files from various sources including local file paths on the n8n server, public URLs, or binary data from previous workflow nodes.

Common scenarios for this node include:

  • Automating sending media or documents to Zalo users or groups.
  • Integrating external file sources or workflow-generated binary data into Zalo conversations.
  • Bulk uploading multiple attachments in one operation.

Practical examples:

  • Uploading a photo stored on the n8n server to a specific Zalo user chat.
  • Downloading an image from a public URL and sending it to a Zalo group.
  • Sending multiple PDF reports generated in a workflow as binary data to a Zalo thread.

Properties

Name Meaning
Thread ID The ID of the Zalo thread (user or group) where the attachment will be uploaded.
Type The type of thread: "User" or "Group".
Attachment Source Source of the attachment file(s): "File Path" (local server), "URL" (public internet URL), or "Binary Data" (from workflow).
File Path Absolute path to a single file on the n8n server (shown if Attachment Source is "File Path" and not multiple files).
File URL Public URL of a single file to upload (shown if Attachment Source is "URL" and not multiple files).
Binary Property Name of the binary property containing file data (shown if Attachment Source is "Binary Data" and not multiple files).
Filename Filename with extension for the binary data file (shown if Attachment Source is "Binary Data" and not multiple files).
Multiple Files Boolean flag indicating whether to upload multiple files at once.
File Paths (Multiple) List of file paths separated by commas or new lines for multiple files upload (shown if Attachment Source is "File Path" and multiple files enabled).
File URLs (Multiple) List of file URLs separated by commas or new lines for multiple files upload (shown if Attachment Source is "URL" and multiple files enabled).
Binary Properties (Multiple) Comma-separated list of binary property names for multiple files upload (shown if Attachment Source is "Binary Data" and multiple files enabled).
Filenames (Multiple) Comma-separated list of filenames with extensions corresponding to each binary property (shown if Attachment Source is "Binary Data" and multiple files enabled).

Output

The node outputs JSON data describing the result of the upload operation:

  • success: Boolean indicating if the upload succeeded.
  • threadId: The target thread ID.
  • type: The thread type ("User" or "Group").
  • uploadedFiles: An array of objects representing each uploaded file, each containing:
    • fileName: The name of the uploaded file.
    • fileType: Type of the file ("image", "video", or others).
    • totalSize: Size of the uploaded file in bytes.
    • For images:
      • fileId: Identifier of the photo.
      • fileUrl: URL to the uploaded image.
      • width, height: Dimensions of the image.
      • hdUrl, thumbUrl: URLs for HD and thumbnail versions.
    • For videos and other files:
      • fileId: Identifier of the file.
      • fileUrl: URL to the uploaded file.
      • checksum: Checksum of the file.

If the node handles binary data input, it temporarily saves the binary content as files before uploading.

Dependencies

  • Requires a valid Zalo API authentication via credentials that provide a cookie, IMEI, and user agent string.
  • Uses the zca-js library for interacting with the Zalo API.
  • Uses Node.js filesystem (fs) and path (path) modules to handle files.
  • Utilizes helper functions to download files from URLs and remove temporary files.
  • Requires proper configuration of the Zalo API credential in n8n with necessary authentication details.

Troubleshooting

  • File Not Found: If a specified local file path does not exist, the node throws an error. Verify the file path is correct and accessible by the n8n process.
  • Binary Property Missing or Invalid: When using binary data, ensure the specified binary property exists and contains valid base64 data.
  • Download Failures: For URL sources, failure to download the file results in an error. Check the URL accessibility and network connectivity.
  • Upload Timeout or Network Errors: The node retries up to 3 times on timeouts, network errors, or server errors. Large files (>10MB) may cause longer upload times and potential timeouts; consider splitting large files.
  • Unsupported File Extensions: Warnings are logged if file extensions might not be supported by Zalo API. Confirm file formats are compatible.
  • Credential Issues: Initialization failures indicate problems with the provided Zalo API credentials. Recheck the cookie and related authentication info.
  • Temporary File Cleanup: Temporary files created during processing are deleted after upload. Failure to delete them logs warnings but does not stop execution.

Links and References

Discussion