xpzouying/xiaohongshu-mcp · error
必须提供本地视频文件
Error message
必须提供本地视频文件
What it means
PublishVideo requires req.Video to be a non-empty path to a local video file. An empty string is rejected immediately with this error before any file system access. The library does not support URL-based video inputs in this code path.
Source
Thrown at service.go:298
action, err := xiaohongshu.NewPublishImageAction(page)
if err != nil {
return err
}
return action.Publish(ctx, content)
}
// PublishVideo 发布视频(本地文件)
func (s *XiaohongshuService) PublishVideo(ctx context.Context, req *PublishVideoRequest) (*PublishVideoResponse, error) {
// 标题长度校验(小红书限制:最大20个字)
if xhsutil.CalcTitleLength(req.Title) > 20 {
return nil, fmt.Errorf("标题长度超过限制")
}
// 本地视频文件校验
if req.Video == "" {
return nil, fmt.Errorf("必须提供本地视频文件")
}
if _, err := os.Stat(req.Video); err != nil {
return nil, fmt.Errorf("视频文件不存在或不可访问: %v", err)
}
var scheduleTime *time.Time
if req.ScheduleAt != "" {
t, err := time.Parse(time.RFC3339, req.ScheduleAt)
if err != nil {
return nil, fmt.Errorf("定时发布时间格式错误,请使用 ISO8601 格式: %v", err)
}
// 校验定时发布时间范围:1小时至14天
now := time.Now()
minTime := now.Add(1 * time.Hour)
maxTime := now.Add(14 * 24 * time.Hour)
if t.Before(minTime) {View on GitHub (pinned to 332d196854)
Solutions
- Set req.Video to the absolute path of an existing local video file before calling PublishVideo
- If the source is remote, download it to a local file first, then pass that path
- Validate req.Video != "" in the handler and return a user-facing message early
Example fix
// before
req := &PublishVideoRequest{Title: t} // Video empty
// after
req := &PublishVideoRequest{Title: t, Video: "/data/videos/clip.mp4"} Defensive patterns
Strategy: validation
Validate before calling
if req.Video == "" {
return errors.New("Video: a local video file path is required")
} Type guard
func hasLocalVideo(req *PublishVideoRequest) bool {
return req != nil && req.Video != ""
} Try / catch
resp, err := svc.PublishVideo(ctx, req)
if err != nil && strings.Contains(err.Error(), "必须提供本地视频文件") {
return fmt.Errorf("video field empty — pass a local file path: %w", err)
} Prevention
- Validate required fields (Title, Video) at the handler boundary before calling the service
- Keep PublishVideoRequest and PublishRequest contracts distinct — Video is local-path-only
- If the source is remote, download to disk first and set Video to that path
When it happens
Trigger: Calling PublishVideo with req.Video == "" — e.g. the caller intended URL publishing, forgot to populate the field, or a previous download step silently failed.
Common situations: Config field left blank; upstream pipeline produced no local video; confusion between PublishContent (images) and PublishVideo (local file) request contracts.
Understand the failure class
Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/d0660162a4037c87.
Report an issue: GitHub.