iflytek/astron-agent · warning · BusinessException

8001

8001

Error message

Invalid file format, please upload a png or jpg image

What it means

ImageController.upload validates the uploaded file's original filename before storing it. If the filename is null or contains no '.', it throws BusinessException(ResponseEnum.RESPONSE_FAILED, code 8001) with message 'Invalid file format, please upload a png or jpg image'. The suffix check cannot run without a dot-separated extension, so the request is rejected up front.

Solutions

  1. Rename the file client-side to include a valid .png/.jpg/.jpeg extension before uploading.
  2. Verify the multipart form field is named 'file' and includes the filename in Content-Disposition.
  3. Send Content-Type multipart/form-data so Spring populates getOriginalFilename() correctly.
  4. If the file is genuinely an image without extension, add the correct extension before upload.

Example fix

// before
const fd = new FormData(); fd.append('file', blob, 'screenshot'); // no extension
// after
const fd = new FormData(); fd.append('file', blob, 'screenshot.png');
Defensive patterns

Strategy: validation

Validate before calling

const name = file?.name || '';
if (!name.includes('.')) { alert('Please choose a png or jpg image'); return; }

Type guard

function hasImageExtension(file) { return /\.(png|jpe?g)$/i.test(file?.name || ''); }

Try / catch

try { await uploadImage(file); } catch (BusinessException e) { if (e.getCode() == 8001) { showToast("Please upload a png or jpg image"); } else throw e; }

Prevention

When it happens

Trigger: POSTing a multipart file to the image upload endpoint where file.getOriginalFilename() is null (no filename part) or has no '.' in it — e.g. a filename like 'image' with no extension.

Common situations: Clients uploading files without extensions; curl uploads using @file with a bare name; programmatic clients constructing MultipartFile wrappers with null filenames; drag-and-drop uploads of extensionless files; some browsers stripping extensions for certain MIME types.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/13bd70c0aca63cf3. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/controller/common/ImageController.java:59

     * </p>
     *
     * @param file multipart file to upload; must not be {@code null}
     * @return {@link ApiResult} wrapping a JSON object containing:
     *         <ul>
     *         <li>{@code s3Key} - object key in S3</li>
     *         <li>{@code downloadLink} - accessible download URL</li>
     *         </ul>
     * @throws BusinessException if the file name is invalid, file suffix is unsupported, or upload
     *         fails
     */
    @PostMapping("/upload")
    public ApiResult<JSONObject> upload(@RequestParam("file") MultipartFile file) {
        // File suffix validation
        List<String> allowedSuffixes = Arrays.asList("png", "jpg", "jpeg");
        String fileName = file.getOriginalFilename();

        if (fileName == null || !fileName.contains(".")) {
            throw new BusinessException(ResponseEnum.RESPONSE_FAILED, "Invalid file format, please upload a png or jpg image");
        }

        String suffix = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase();
        if (!allowedSuffixes.contains(suffix)) {
            throw new BusinessException(ResponseEnum.RESPONSE_FAILED, "Invalid file format, please upload a png or jpg image");
        }

        String s3Key = imageService.upload(file);
        JSONObject res = new JSONObject();
        // Generate unique file name
        res.put("s3Key", s3Key);
        res.put("downloadLink", s3UtilClient.getS3Url(s3Key));
        return ApiResult.success(res);
    }
}

View on GitHub (pinned to 5e758547a8)