iflytek/astron-agent · error · BusinessException

99999

99999

Error message

system.error

What it means

When the Base64 decode itself fails (e.g. the string contains illegal characters or wrong padding), the method catches the exception, logs it, and rethrows the generic BusinessException SYSTEM_ERROR (code 99999). The generic code hides the real decode failure, so check the server log for 'Failed to convert Base64 string to InputStream'.

Solutions

  1. Inspect the server log at ImageUtil.java for the wrapped stack trace to see the actual decoder error
  2. Strip the "data:image/...;base64," prefix before passing the string
  3. Validate the string matches ^[A-Za-z0-9+/]*={0,2}$ and has length % 4 == 0 before calling
  4. If the source uses URL-safe Base64, convert '-'->'+' and '_'->'/' and re-pad before decoding

Example fix

// before
InputStream in = ImageUtil.base64ToImageInputStream(dataUrl); // "data:image/png;base64,iVBOR..."
// after
String b64 = dataUrl.substring(dataUrl.indexOf(",") + 1); // strip data-URL prefix
InputStream in = ImageUtil.base64ToImageInputStream(b64);
Defensive patterns

Strategy: validation

Validate before calling

boolean isRawBase64(String s) { return s != null && s.matches("^[A-Za-z0-9+/\\r\\n]+={0,2}$") && s.replaceAll("\\s", "").length() % 4 == 0; }

Try / catch

try { InputStream in = ImageUtil.base64ToImageInputStream(b64); } catch (BusinessException e) { log.error("base64 image decode failed for request {}", reqId, e); throw new BadRequestException("invalid image data"); }

Prevention

When it happens

Trigger: Passing a string that is not valid Base64: contains characters outside the Base64 alphabet, wrong length not a multiple of 4, missing/incorrect padding, or a full data URL like "data:image/png;base64,AAAA" passed without stripping the prefix.

Common situations: Frontend sends a data-URI instead of raw Base64, URL-safe Base64 (-/_) used where standard Base64 (+//) is expected, copy-paste truncating the string, or JSON transport mangling '+' characters in form-encoded requests.

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/9beef97edb8e3831. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/ImageUtil.java:38

public class ImageUtil {

    /**
     * Convert base64 string to InputStream
     *
     * @param base64String Base64 encoded image string
     * @return InputStream object
     */
    public static InputStream base64ToImageInputStream(String base64String) {
        if (base64String == null || base64String.trim().isEmpty()) {
            throw new IllegalArgumentException("Base64 string cannot be empty");
        }

        try {
            byte[] byteArray = Base64.getDecoder().decode(base64String);
            return new ByteArrayInputStream(byteArray);
        } catch (Exception e) {
            log.error("Failed to convert Base64 string to InputStream", e);
            throw new BusinessException(SYSTEM_ERROR);
        }
    }

    /**
     * Compress image
     *
     * @param inputStream Original image input stream
     * @param scale Compression ratio (0.0-1.0)
     * @return Compressed image input stream
     */
    public static InputStream compressImage(InputStream inputStream, float scale) {
        if (inputStream == null) {
            throw new IllegalArgumentException("Input stream cannot be empty");
        }
        if (scale <= 0 || scale > 1) {
            throw new IllegalArgumentException("Compression ratio must be between 0-1");
        }

View on GitHub (pinned to 5e758547a8)