{"record":{"id":"4c1569dc44bd5659","repo":"siyuan-note/siyuan","slug":"open-form-part-s-file-s-error-s","errorCode":null,"errorMessage":"open form part [%s] file [%s] error: %s","messagePattern":"open form part \\[(.+?)\\] file \\[(.+?)\\] error: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/server.go","lineNumber":327,"sourceCode":"\t} else if multipartForm != nil {\n\t\t// multipart/form-data\n\t\tform = &RequestForm{\n\t\t\tValue: multipartForm.Value,\n\t\t\tFile:  make(map[string][]*RequestFile),\n\t\t}\n\n\t\tfor partName, fileHandlers := range multipartForm.File {\n\t\t\tfiles := make([]*RequestFile, len(fileHandlers))\n\t\t\tform.File[partName] = files\n\t\t\tfor i, handler := range fileHandlers {\n\t\t\t\tfiles[i] = &RequestFile{\n\t\t\t\t\tFilename: handler.Filename,\n\t\t\t\t\tHeaders:  handler.Header,\n\t\t\t\t\tSize:     handler.Size,\n\t\t\t\t}\n\t\t\t\tfile, openErr := handler.Open()\n\t\t\t\tif openErr != nil {\n\t\t\t\t\terr = fmt.Errorf(\"open form part [%s] file [%s] error: %s\", partName, handler.Filename, openErr.Error())\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tcontent := make([]byte, handler.Size)\n\t\t\t\tn, readErr := file.Read(content)\n\t\t\t\tfile.Close()\n\t\t\t\tif readErr != nil {\n\t\t\t\t\terr = fmt.Errorf(\"read form part [%s] file [%s] error: %s\", partName, handler.Filename, readErr.Error())\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tfileData := content[:n]\n\t\t\t\tfiles[i].Data = &fileData\n\t\t\t}\n\t\t}\n\t} else if len(c.Request.PostForm) > 0 {\n\t\t// application/x-www-form-urlencoded\n\t\tform = &RequestForm{\n\t\t\tValue: c.Request.PostForm,\n\t\t\tFile:  nil,","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/plugin/server.go#L309-L345","documentation":"Returned while parsing a multipart/form-data request in the plugin server: handler.Open() failed for one of the uploaded files in a form part. Wraps the underlying open error; identifies the part name and filename. The whole form-parse function returns this error and aborts request handling.","triggerScenarios":"A plugin's request handler receives a multipart upload; for one file part, the multipart header's Open() (mime/multipart) fails — e.g. the part was already consumed, the temp file backing was removed, or the reader encountered a stream error.","commonSituations":"The request body was partially read/streamed before the handler; large uploads where the temp file is cleaned mid-read; client aborted mid-upload; double-parsing the same multipart form (Open can only be called once per part in some drivers).","solutions":["Ensure the multipart form is parsed exactly once per request (do not call c.MultipartForm twice or pre-read the body).","Increase request body / temp limits if large uploads fail mid-stream.","If the client aborted, surface a 4xx and retry the upload."],"exampleFix":"// before\nbody, _ := c.GetRawData() // consumes body\nform, _ := c.MultipartForm() // then Open() fails\n// after\nform, _ := c.MultipartForm() // parse once; do not pre-read raw body","handlingStrategy":"try-catch","validationCode":"// Caller side: ensure body is multipart and not pre-consumed.\nfunction isMultipart(req: Request): boolean {\n  return (req.headers.get('content-type') ?? '').toLowerCase().startsWith('multipart/form-data')\n}","typeGuard":null,"tryCatchPattern":"// Plugin server: parse the form once, handle errors per part.\ntry { form, err := c.MultipartForm() }\ncatch (e) {\n  if (/open form part/i.test(String(e))) return c.String(400, 'upload part unreadable: ' + e)\n  throw e\n}","preventionTips":["Parse multipart exactly once per request; do not pre-read the raw body.","Set adequate body/temp size limits for large uploads.","Surface client aborts as 4xx and let the client retry."],"tags":["plugin","multipart","upload","http","form-parse"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}