elunez/eladmin · error · BadRequestException
存储桶不存在,请检查配置或权限。
Error message
存储桶不存在,请检查配置或权限。
What it means
Thrown by S3StorageServiceImpl.deleteAll before deleting any objects: it heads the bucket configured as amzS3Config.getDefaultBucket(), and if bucketExists() reports it missing (or the head call failed with a non-404 S3Exception — see error 96 for that branch), the bulk delete is refused. The 404 branch inside bucketExists logs '存储桶不存在' and returns false, which surfaces here.
Source
Thrown at eladmin-tools/src/main/java/me/zhengjie/service/impl/S3StorageServiceImpl.java:83
public PageResult<S3Storage> queryAll(S3StorageQueryCriteria criteria, Pageable pageable){
Page<S3Storage> page = s3StorageRepository.findAll((root, criteriaQuery, criteriaBuilder)
-> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page);
}
@Override
public List<S3Storage> queryAll(S3StorageQueryCriteria criteria){
return s3StorageRepository.findAll((root, criteriaQuery, criteriaBuilder)
-> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(List<Long> ids) {
// 检查桶是否存在
String bucketName = amzS3Config.getDefaultBucket();
if (!bucketExists(bucketName)) {
throw new BadRequestException("存储桶不存在,请检查配置或权限。");
}
// 遍历 ID 列表,删除对应的文件和数据库记录
for (Long id : ids) {
String filePath = s3StorageRepository.selectFilePathById(id);
if (filePath == null) {
System.err.println("未找到 ID 为 " + id + " 的文件记录,无法删除。");
continue;
}
try {
// 创建 DeleteObjectRequest,指定存储桶和文件键
DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder()
.bucket(bucketName)
.key(filePath)
.build();
// 调用 deleteObject 方法
s3Client.deleteObject(deleteObjectRequest);
// 删除数据库数据
s3StorageRepository.deleteById(id);View on GitHub (pinned to 55fbf70595)
Solutions
- Verify the default bucket name in the S3 storage config matches an existing bucket (aws s3 ls or the MinIO console).
- Check region/endpoint in amzS3Config — a head-bucket against the wrong region can 404/301.
- Confirm the credentials in use belong to the account owning the bucket (a 403 is reported as error 96 instead).
- If the bucket was intentionally removed, clean up the s3_storage DB records so deleteAll is not called against stale metadata.
- Create the bucket (or upload once, which auto-creates it via createBucket) before using delete.
Example fix
// before
String bucketName = amzS3Config.getDefaultBucket();
if (!bucketExists(bucketName)) {
throw new BadRequestException("存储桶不存在,请检查配置或权限。");
}
// after: report which bucket failed to make ops actionable
String bucketName = amzS3Config.getDefaultBucket();
if (!bucketExists(bucketName)) {
throw new BadRequestException("存储桶 " + bucketName + " 不存在,请检查配置或权限。");
} Defensive patterns
Strategy: validation
Validate before calling
// verify bucket resolvable before issuing batch delete
String bucket = amzS3Config.getDefaultBucket();
if (!s3Client.listBuckets().buckets().stream().anyMatch(b -> b.name().equals(bucket))) {
throw new BadRequestException("配置的存储桶不存在,请先修正配置");
} Try / catch
try { s3StorageService.deleteAll(ids); } catch (BadRequestException e) { if (e.getMessage().contains("存储桶不存在")) { /* config problem: stop and fix bucket name/endpoint, do not retry */ } } Prevention
- Validate the bucket name with a head-bucket when saving S3 config in the admin UI.
- Keep bucket/endpoint/region/credentials as one reviewed unit — changing one without the others causes this.
- After renaming buckets, migrate objects AND update config together.
When it happens
Trigger: DELETE /s3Storage (batch ids) when the configured default bucket name doesn't exist in the S3 account — typo in config, wrong region endpoint, credentials pointing at another account, or the bucket was deleted out-of-band.
Common situations: amz-s3 config (bucket name / endpoint / region / keys) entered incorrectly in the admin S3 config page; using a MinIO/other S3-compatible endpoint where the bucket was never created; IAM keys rotated to an account without that bucket; bucket removed while DB records still reference it.
Related errors
AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14).
Data as JSON: /api/errors/646cca67da5a1eb4.
Report an issue: GitHub.