alibaba/spring-ai-alibaba · error · BizException
OSS_GEN_URL_ERROR
OSS_GEN_URL_ERROR
Error message
OSS generate url error
What it means
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.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/OssManager.java:222
}
public String generateURL(String objectName) {
long start = System.currentTimeMillis();
String safeObjectName = trimObjectName(objectName);
if (StringUtils.isBlank(objectName)) {
throw new IllegalArgumentException("oss object name is invalid");
}
try {
String bucketName = getBucket();
Date expiration = new Date(System.currentTimeMillis() + URl_EXPIRE_TIME.toMillis());
URL url = ossClient.generatePresignedUrl(bucketName, safeObjectName, expiration);
LogUtils.monitor("ossManager", "generateURL", start, SUCCESS, objectName, url);
return url.toString().replace("http://", "https://");
}
catch (Exception e) {
LogUtils.monitor("ossManager", "generateURL", start, SUCCESS, objectName, null, e);
throw new BizException(ErrorCode.OSS_GEN_URL_ERROR.toError(), e);
}
}
/**
* download file as string
* @param objectName object name
* @return file content
*/
public String downloadFileAsString(String objectName) {
long start = System.currentTimeMillis();
InputStream is = null;
OSSObject ossObject = null;
ByteArrayOutputStream bos = null;
try {
String bucketName = getBucket();
ossObject = ossClientInternal.getObject(bucketName, objectName);View on GitHub (pinned to f82da0b50f)
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
Example fix
// before
String url = ossManager.generateURL(objectName);
// after
try {
String url = ossManager.generateURL(objectName);
} catch (BizException e) {
log.error("Presigned URL generation failed for {}", objectName, e.getCause());
throw new ServiceException("Cannot generate download link", e);
} Defensive patterns
Strategy: try-catch
Validate before calling
if (objectName == null || objectName.isBlank()) return null; // ensure OSS configured if (ossProperties.getBucket() == null || ossProperties.getAccessKeyId() == null) return null;
Type guard
boolean isPresignFailure(BizException e) {
return e.getError() != null && "OSS_GEN_URL_ERROR".equals(e.getError().getCode());
} Try / catch
try {
return ossManager.generateURL(objectName);
} catch (BizException e) {
if (isPresignFailure(e)) {
log.error("Presign failed for {}", objectName, e.getCause());
return null;
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- OSS_UPLOAD_ERROR
- OSS_DOWNLOAD_ERROR
- oss object name is invalid
- oss ak or sk should be set.
- oss bucket should be set.
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/44a1fbdfd89b2a71.
Report an issue: GitHub.