{"record":{"id":"033dd6dc3868bad4","repo":"Tencent/WeKnora","slug":"failed-to-generate-oss-presigned-url-w","errorCode":null,"errorMessage":"failed to generate OSS presigned URL: %w","messagePattern":"failed to generate OSS presigned URL: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/oss.go","lineNumber":362,"sourceCode":"\tif err := utils.SafeObjectKey(objectName); err != nil {\n\t\treturn \"\", fmt.Errorf(\"invalid file path: %w\", err)\n\t}\n\n\t// Determine which client to use\n\tvar client *oss.Client\n\tif bucketName == s.tempBucketName && s.tempClient != nil {\n\t\tclient = s.tempClient\n\t} else {\n\t\tclient = s.client\n\t}\n\n\t// Generate presigned URL (valid for 24 hours)\n\tresult, err := client.Presign(ctx, &oss.GetObjectRequest{\n\t\tBucket: oss.Ptr(bucketName),\n\t\tKey:    oss.Ptr(objectName),\n\t}, oss.PresignExpires(24*time.Hour))\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to generate OSS presigned URL: %w\", err)\n\t}\n\n\treturn result.URL, nil\n}\n","sourceCodeStart":344,"sourceCodeEnd":367,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/oss.go#L344-L367","documentation":"This wraps a failure from the OSS SDK's client.Presign call, which generates a 24-hour presigned GET URL. Presigning can fail due to invalid credentials/region config, malformed GetObjectRequest, or unsupported client configuration. The URL was never produced, so the caller receives no download link.","triggerScenarios":"Calling GetFileURL when the OSS client has no valid signing credentials, the region/endpoint is wrong for the bucket, or the GetObjectRequest fields are empty/invalid.","commonSituations":"Missing or expired access-key configuration for the OSS client, anonymous clients that cannot sign, misconfigured custom endpoint/region, clock skew on the host (can surface as signature errors downstream).","solutions":["Verify the OSS client's credentials (AK/SK or STS) are set and valid","Check bucket region matches the client's configured region/endpoint","Log the wrapped SDK error to identify the exact presign failure","Shorten/recheck the 24h expiry if policy limits max presign duration"],"exampleFix":"// before\nresult, err := client.Presign(ctx, req, oss.PresignExpires(24*time.Hour))\nif err != nil { return \"\", fmt.Errorf(\"failed to generate OSS presigned URL: %w\", err) }\n// after\nresult, err := client.Presign(ctx, req, oss.PresignExpires(24*time.Hour))\nif err != nil {\n    return \"\", fmt.Errorf(\"failed to generate OSS presigned URL: %w\", err) // inspect %w for credential/region cause\n}","handlingStrategy":"try-catch","validationCode":"if bucket == \"\" || objectKey == \"\" { return errors.New(\"bucket and key required before presign\") }","typeGuard":null,"tryCatchPattern":"url, err := svc.GetFileURL(ctx, path)\nif err != nil {\n    var e *os.PathError\n    if errors.Is(err, context.DeadlineExceeded) { /* retry with backoff */ }\n    return fmt.Errorf(\"presign failed: %w\", err)\n}","preventionTips":["Verify OSS client credentials are configured before presigning","Keep host clocks synchronized (signature validity)","Match client region/endpoint to the bucket region","Retry transient presign failures with exponential backoff"],"tags":["oss","presigned-url","signing","network"],"backgroundTag":"presign-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}