AlistGo/alist · error

file size cannot be zero

Error message

file size cannot be zero

What it means

Returned by BaiduPhoto.Put (drivers/baidu_photo/driver.go:240) when the upload stream reports a size of 0 bytes. The Baidu Photo union upload API has no way to upload empty content (its slice/md5 upload protocol needs at least one block), so the driver rejects empty files locally before any network request is made. This is a pre-condition guard, not a server-side error.

Source

Thrown at drivers/baidu_photo/driver.go:240

	return nil, errs.NotSupport
}

func (d *BaiduPhoto) Remove(ctx context.Context, obj model.Obj) error {
	switch obj := obj.(type) {
	case *File:
		return d.DeleteFile(ctx, obj)
	case *AlbumFile:
		return d.DeleteAlbumFile(ctx, obj)
	case *Album:
		return d.DeleteAlbum(ctx, obj)
	}
	return errs.NotSupport
}

func (d *BaiduPhoto) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) (model.Obj, error) {
	// 不支持大小为0的文件
	if stream.GetSize() == 0 {
		return nil, fmt.Errorf("file size cannot be zero")
	}

	// TODO:
	// 暂时没有找到妙传方式
	var (
		cache = stream.GetFile()
		tmpF  *os.File
		err   error
	)
	if _, ok := cache.(io.ReaderAt); !ok {
		tmpF, err = os.CreateTemp(conf.Conf.TempDir, "file-*")
		if err != nil {
			return nil, err
		}
		defer func() {
			_ = tmpF.Close()
			_ = os.Remove(tmpF.Name())
		}()

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Skip zero-byte files in the caller before invoking Put (they cannot be represented in Baidu Photo)
  2. If an empty marker file matters, track it outside the driver (database/metadata) instead of uploading
  3. Filter empty files at the sync layer with a size check and log the skip

Example fix

// before
err := fs.Put(ctx, dstDir, stream, progress)
// stream.GetSize() == 0 -> "file size cannot be zero"

// after
if stream.GetSize() == 0 {
    log.Printf("skipping empty file: %s", stream.GetName())
    return nil
}
err := fs.Put(ctx, dstDir, stream, progress)
Defensive patterns

Strategy: validation

Validate before calling

// before upload
if stream.GetSize() == 0 {
    log.Printf("baidu_photo: skipping empty file %q (zero-size uploads unsupported)", stream.GetName())
    return nil
}
obj, err := driver.Put(ctx, dstDir, stream, up)

Prevention

When it happens

Trigger: Calling driver.Put (or any upload/copy-to-baidu-photo path) with a 0-byte file: streams whose GetSize() == 0, e.g. uploading an empty placeholder file created with touch.

Common situations: Sync/mirror tools that copy directory trees containing .gitkeep, lock files, or build artifacts that are empty; automated pipelines uploading generated-but-empty logs or placeholders.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/398775cbd90cdcf7. Report an issue: GitHub.