AlistGo/alist · error

upload tk is empty

Error message

upload tk is empty

What it means

Thrown by openFinalizeUpload during an api_key-mode Yunpan360 upload when the server's upload response does not auto-commit and contains no "tk" token. After uploading file bytes, some flows require a second Sync.addFileToApi call signed with tk to register the file; a missing tk (trimmed empty) means the finalize step cannot be signed or sent, so the upload would strand as orphaned data.

Source

Thrown at drivers/yunpan360/upload.go:462

	url := buildJSQueryURL(d.uploadBaseURL(addrResp), "Upload.commit4Web", d.uploadDataParams(auth, plan))
	url = appendHostQuery(url, addrResp.Data.HTTP)

	var resp openUploadFinalizeResp
	err = d.uploadRequest(ctx, http.MethodPost, url, auth.AccessToken, contentType, body, &resp)
	if err != nil {
		return nil, err
	}
	return &resp, nil
}

func (d *Yunpan360) openFinalizeUpload(ctx context.Context, auth *OpenAuthInfo, resp *openUploadFinalizeResp) error {
	if resp == nil || resp.autoCommit() {
		return nil
	}
	tk := strings.TrimSpace(resp.stringValue("tk"))
	if tk == "" {
		return errors.New("upload tk is empty")
	}

	signParams := map[string]string{
		"tk": tk,
	}
	body, contentType, err := createMultipartForm("", map[string]string{
		"qid":  auth.Qid,
		"tk":   tk,
		"sign": openSign(auth.AccessToken, auth.Qid, "Sync.addFileToApi", signParams),
	}, nil)
	if err != nil {
		return err
	}

	return d.uploadRequest(ctx, http.MethodPost, buildJSQueryURL(openAPIURL(d.EcsEnv), "Sync.addFileToApi", nil), auth.AccessToken, contentType, body, nil)
}

func (d *Yunpan360) findUploadedObject(ctx context.Context, targetPath string) (model.Obj, error) {

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Retry the whole upload from the start so a fresh auth token and upload session are used
  2. Confirm the open auth credentials (api_key, qid) are current by re-saving the storage config
  3. Update the yunpan360 driver if the finalize protocol changed server-side
Defensive patterns

Strategy: retry

Try / catch

if err != nil && strings.Contains(err.Error(), "upload tk is empty") {
    // finalize handshake desynced: restart upload with fresh auth
    return d.Put(ctx, dstDir, file, up)
}

Prevention

When it happens

Trigger: The upload endpoint returns a JSON envelope where autoCommit is false and the tk field is absent or empty — typically because the session/upload handshake is out of sync (stale auth token, mismatched qid) or the server changed the finalize protocol.

Common situations: Long-running uploads whose open auth token expired mid-flight; multi-step uploads interrupted and retried at the wrong phase; API-side changes to the finalize handshake; large-file paths that behave differently from simple ones.

Related errors


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