{"record":{"id":"398775cbd90cdcf7","repo":"AlistGo/alist","slug":"file-size-cannot-be-zero","errorCode":null,"errorMessage":"file size cannot be zero","messagePattern":"file size cannot be zero","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/baidu_photo/driver.go","lineNumber":240,"sourceCode":"\treturn nil, errs.NotSupport\n}\n\nfunc (d *BaiduPhoto) Remove(ctx context.Context, obj model.Obj) error {\n\tswitch obj := obj.(type) {\n\tcase *File:\n\t\treturn d.DeleteFile(ctx, obj)\n\tcase *AlbumFile:\n\t\treturn d.DeleteAlbumFile(ctx, obj)\n\tcase *Album:\n\t\treturn d.DeleteAlbum(ctx, obj)\n\t}\n\treturn errs.NotSupport\n}\n\nfunc (d *BaiduPhoto) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) (model.Obj, error) {\n\t// 不支持大小为0的文件\n\tif stream.GetSize() == 0 {\n\t\treturn nil, fmt.Errorf(\"file size cannot be zero\")\n\t}\n\n\t// TODO:\n\t// 暂时没有找到妙传方式\n\tvar (\n\t\tcache = stream.GetFile()\n\t\ttmpF  *os.File\n\t\terr   error\n\t)\n\tif _, ok := cache.(io.ReaderAt); !ok {\n\t\ttmpF, err = os.CreateTemp(conf.Conf.TempDir, \"file-*\")\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tdefer func() {\n\t\t\t_ = tmpF.Close()\n\t\t\t_ = os.Remove(tmpF.Name())\n\t\t}()","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/baidu_photo/driver.go#L222-L258","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Skip zero-byte files in the caller before invoking Put (they cannot be represented in Baidu Photo)","If an empty marker file matters, track it outside the driver (database/metadata) instead of uploading","Filter empty files at the sync layer with a size check and log the skip"],"exampleFix":"// before\nerr := fs.Put(ctx, dstDir, stream, progress)\n// stream.GetSize() == 0 -> \"file size cannot be zero\"\n\n// after\nif stream.GetSize() == 0 {\n    log.Printf(\"skipping empty file: %s\", stream.GetName())\n    return nil\n}\nerr := fs.Put(ctx, dstDir, stream, progress)","handlingStrategy":"validation","validationCode":"// before upload\nif stream.GetSize() == 0 {\n    log.Printf(\"baidu_photo: skipping empty file %q (zero-size uploads unsupported)\", stream.GetName())\n    return nil\n}\nobj, err := driver.Put(ctx, dstDir, stream, up)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter zero-byte files (.gitkeep, lock files, empty logs) in the sync layer before copying to Baidu Photo","Treat 'file size cannot be zero' as a permanent skip condition, never retry it","Log skipped files so mirror diffs stay explainable"],"tags":["upload","validation","baidu-photo","go"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}