{"record":{"id":"44a1fbdfd89b2a71","repo":"alibaba/spring-ai-alibaba","slug":"oss-gen-url-error","errorCode":"OSS_GEN_URL_ERROR","errorMessage":"OSS generate url error","messagePattern":"OSS generate url error","errorType":"error_code","errorClass":"BizException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/OssManager.java","lineNumber":222,"sourceCode":"\t}\n\n\tpublic String generateURL(String objectName) {\n\t\tlong start = System.currentTimeMillis();\n\t\tString safeObjectName = trimObjectName(objectName);\n\t\tif (StringUtils.isBlank(objectName)) {\n\t\t\tthrow new IllegalArgumentException(\"oss object name is invalid\");\n\t\t}\n\n\t\ttry {\n\t\t\tString bucketName = getBucket();\n\t\t\tDate expiration = new Date(System.currentTimeMillis() + URl_EXPIRE_TIME.toMillis());\n\t\t\tURL url = ossClient.generatePresignedUrl(bucketName, safeObjectName, expiration);\n\t\t\tLogUtils.monitor(\"ossManager\", \"generateURL\", start, SUCCESS, objectName, url);\n\t\t\treturn url.toString().replace(\"http://\", \"https://\");\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tLogUtils.monitor(\"ossManager\", \"generateURL\", start, SUCCESS, objectName, null, e);\n\t\t\tthrow new BizException(ErrorCode.OSS_GEN_URL_ERROR.toError(), e);\n\t\t}\n\t}\n\n\t/**\n\t * download file as string\n\t * @param objectName object name\n\t * @return file content\n\t */\n\tpublic String downloadFileAsString(String objectName) {\n\t\tlong start = System.currentTimeMillis();\n\n\t\tInputStream is = null;\n\t\tOSSObject ossObject = null;\n\t\tByteArrayOutputStream bos = null;\n\t\ttry {\n\t\t\tString bucketName = getBucket();\n\n\t\t\tossObject = ossClientInternal.getObject(bucketName, objectName);","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/OssManager.java#L204-L240","documentation":"OssManager.generateURL wraps any failure while generating a presigned URL in BizException(OSS_GEN_URL_ERROR, 'OSS generate url error'). After the blank-name guard passes, ossClient.generatePresignedUrl(bucketName, safeObjectName, expiration) can still fail (client not initialized, invalid credentials, OSS SDK error); such exceptions are logged and rethrown as this BizException with the cause attached.","triggerScenarios":"Calling generateURL with a valid but problematic objectName when the OSS client is misconfigured (bad ak/sk/region), the bucket is missing (getBucket throws first only in internal paths), or the SDK rejects the key/expiry.","commonSituations":"Wrong region/endpoint so the signing request targets a nonexistent bucket; expired or invalid credentials; object name containing characters OSS rejects even after trimming; OSS client bean failed to initialize (see error 27/28).","solutions":["Inspect the cause exception in the BizException for the exact SDK error","Verify oss.access-key-id/secret/region/bucket configuration is valid","Ensure OssManager.afterPropertiesSet succeeded (credentials and bucket set)","Sanitize the objectName to OSS-legal characters before calling","Retry for transient network errors"],"exampleFix":"// before\nString url = ossManager.generateURL(objectName);\n// after\ntry {\n    String url = ossManager.generateURL(objectName);\n} catch (BizException e) {\n    log.error(\"Presigned URL generation failed for {}\", objectName, e.getCause());\n    throw new ServiceException(\"Cannot generate download link\", e);\n}","handlingStrategy":"try-catch","validationCode":"if (objectName == null || objectName.isBlank()) return null;\n// ensure OSS configured\nif (ossProperties.getBucket() == null || ossProperties.getAccessKeyId() == null) return null;","typeGuard":"boolean isPresignFailure(BizException e) {\n    return e.getError() != null && \"OSS_GEN_URL_ERROR\".equals(e.getError().getCode());\n}","tryCatchPattern":"try {\n    return ossManager.generateURL(objectName);\n} catch (BizException e) {\n    if (isPresignFailure(e)) {\n        log.error(\"Presign failed for {}\", objectName, e.getCause());\n        return null;\n    }\n    throw e;\n}","preventionTips":["Verify ak/sk/region/bucket config is valid in the environment","Sanitize object names to OSS-legal characters before presigning","Confirm OssManager initialized successfully at startup"],"tags":["oss","presigned-url","storage"],"backgroundTag":"api-error-response","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}