{"record":{"id":"d5938859b9f89ced","repo":"AlistGo/alist","slug":"file-name-is-empty","errorCode":null,"errorMessage":"file name is empty","messagePattern":"file name is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"drivers/guangyapan/driver.go","lineNumber":389,"sourceCode":"\tif taskID == \"\" {\n\t\treturn nil\n\t}\n\treturn d.waitTaskDone(ctx, taskID)\n}\n\nfunc (d *GuangYaPan) Put(ctx context.Context, dstDir model.Obj, file model.FileStreamer, up driver.UpdateProgress) error {\n\tif err := d.ensureAccessToken(ctx); err != nil {\n\t\treturn err\n\t}\n\tif file == nil {\n\t\treturn errors.New(\"file is nil\")\n\t}\n\tif file.GetSize() < 0 {\n\t\treturn errors.New(\"invalid file size\")\n\t}\n\tname := strings.TrimSpace(file.GetName())\n\tif name == \"\" {\n\t\treturn errors.New(\"file name is empty\")\n\t}\n\n\tparentID := dstDir.GetID()\n\n\ttoken, code, err := d.getUploadToken(ctx, parentID, name, file.GetSize())\n\tif err != nil {\n\t\treturn err\n\t}\n\ttaskID := strings.TrimSpace(token.TaskID)\n\tif code == 156 {\n\t\tif taskID == \"\" {\n\t\t\treturn errors.New(\"instant upload returns empty task id\")\n\t\t}\n\t\treturn d.waitUploadTaskInfo(ctx, taskID)\n\t}\n\n\tif token.ObjectPath == \"\" || token.BucketName == \"\" || token.EndPoint == \"\" || token.AccessKeyID == \"\" || token.SecretAccessKey == \"\" {\n\t\treturn errors.New(\"upload token is incomplete\")","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/guangyapan/driver.go#L371-L407","documentation":"GuangYaPan Put trims the file name and rejects empty values before requesting an upload token, because the token request is parameterized by file name and the OSS object path is derived from it.","triggerScenarios":"Uploading a streamer whose GetName() is empty or whitespace-only — malformed multipart filename field, or a programmatically built streamer with an unset name.","commonSituations":"Clients omitting filename in multipart forms; scripts creating streamers with an empty Name field; files whose name resolves to only spaces.","solutions":["Ensure the client sends a valid filename in the multipart part / headers","Set streamer Name from the actual file path base when constructing it programmatically","Validate name is non-empty after trimming before calling Put"],"exampleFix":"// before\nstream := model.NewFileStream(&model.Obj{Name: \"\"}, r)\n// after\nname := filepath.Base(path)\nif strings.TrimSpace(name) == \"\" || name == \".\" { return errors.New(\"filename required\") }\nstream := model.NewFileStream(&model.Obj{Name: name, Size: size}, r)","handlingStrategy":"validation","validationCode":"name := strings.TrimSpace(file.GetName())\nif name == \"\" {\n\treturn errors.New(\"file name is required for upload\")\n}\nreturn d.Put(ctx, dstDir, file, up)","typeGuard":"func hasFileName(f model.FileStreamer) bool { return f != nil && strings.TrimSpace(f.GetName()) != \"\" }","tryCatchPattern":null,"preventionTips":["Always set filename in multipart parts and headers","Derive streamer names from filepath.Base when building programmatically","Reject empty filenames at the API gateway before they reach drivers"],"tags":["guangyapan","upload","validation","filename"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}