dutchcoders/transfer.sh · error
Could not encode metadata
Error message
Could not encode metadata
What it means
postHandler builds a metadata struct (content type, length, download limits, deletion token, encryption flag) and encodes it as JSON into a buffer before storing it as `<filename>.metadata`. If json.Encoder.Encode returns an error, the server responds with 500 and this message. In practice this is nearly unreachable: the metadata struct contains only JSON-serializable types, so the encoder essentially never fails.
Source
Thrown at server/handlers.go:522
if err != nil {
s.logger.Printf("%s", err.Error())
http.Error(w, "Could not perform prescan", http.StatusInternalServerError)
return
}
if status != clamavScanStatusOK {
s.logger.Printf("prescan positive: %s", status)
http.Error(w, "Clamav prescan found a virus", http.StatusPreconditionFailed)
return
}
}
metadata := metadataForRequest(contentType, contentLength, s.randomTokenLength, r)
buffer := &bytes.Buffer{}
if err := json.NewEncoder(buffer).Encode(metadata); err != nil {
s.logger.Printf("%s", err.Error())
http.Error(w, "Could not encode metadata", http.StatusInternalServerError)
return
} else if err := s.storage.Put(r.Context(), token, fmt.Sprintf("%s.metadata", filename), buffer, "text/json", uint64(buffer.Len())); err != nil {
s.logger.Printf("%s", err.Error())
http.Error(w, "Could not save metadata", http.StatusInternalServerError)
return
}
s.logger.Printf("Uploading %s %s %d %s", token, filename, contentLength, contentType)
reader, err := attachEncryptionReader(file, r.Header.Get("X-Encrypt-Password"))
if err != nil {
http.Error(w, "Could not crypt file", http.StatusInternalServerError)
return
}
if err = s.storage.Put(r.Context(), token, filename, reader, contentType, uint64(contentLength)); err != nil {View on GitHub (pinned to c37bfd9579)
Solutions
- Inspect the server log printed just before the response; it contains the underlying encoding error.
- If you modified the metadata struct, remove or fix the unserializable field (add a MarshalJSON or drop the field).
- Upgrade to a stock release of the server where this path is effectively dead code.
- Retry the upload — no client-side state is corrupted, nothing was written to storage.
Example fix
// before: unserializable field added to metadata // Files []os.File // after: store only serializable data // FileNames []string
Defensive patterns
Strategy: retry
Try / catch
resp, err := http.Post(url, mime, body)
if err == nil && resp.StatusCode == http.StatusInternalServerError &&
strings.Contains(readBody(resp), "Could not encode metadata") {
return fmt.Errorf("server-side metadata encoding bug; report to operator")
} Prevention
- Run stock server releases — this path is dead code upstream.
- If you maintain the server, keep the metadata struct JSON-serializable.
- Log the underlying encode error server-side for diagnosis.
- Retry is safe; nothing was persisted.
When it happens
Trigger: json.NewEncoder(buffer).Encode(metadata) returns an error — theoretically only if a value in the metadata struct becomes unserializable (e.g. a custom type with a broken MarshalJSON); not triggerable by any client request input.
Common situations: Seen only when the code has been modified to put unsupported types (channels, funcs, invalid UTF-8 handled by custom marshalers) into the metadata struct; stock deployments never produce this.
Related errors
- could not encode metadata
- Clamav prescan found a virus
- Could not save metadata
- Could not crypt file
- maxDownloads expired
AI-assisted analysis of dutchcoders/transfer.sh@c37bfd9579 (2026-09-05).
Data as JSON: /api/errors/2ef94b4d091c9274.
Report an issue: GitHub.