Skip to content

Image upload fails with "Cannot read properties of null" after upgrading to v2.0.0 #1516

@YongJie-Xie

Description

@YongJie-Xie

Describe the bug

After upgrading from a previous version to Answer v2.0.0, attempting to upload an image triggers a runtime exception, and the upload fails. The browser console reports the error: Cannot read properties of null.

To Reproduce

Steps to reproduce the behavior:

  1. Upgrade the Answer instance to version 2.0.0.
  2. Log in as a user.
  3. Go to create a new Question or Answer.
  4. Click the Image Upload icon in the editor toolbar.
  5. Select an image file to upload.
  6. See the error in the console and observe that the image does not appear.

Expected behavior

The image should upload successfully and display in the editor.

Screenshots

Image

Platform

  • Device: Desktop
  • OS: Windows
  • Browser: Chrome latest
  • Version: v2.0.0

Additional Context / Workaround

Workaround:
To temporarily fix this issue without redeploying:

  1. Go to Admin > Advanced > Files.
  2. Default configuration:
  "max_image_size": 4,
  "max_attachment_size": 8,
  "max_image_megapixel": 40,
  "authorized_image_extensions": [
    "jpg",
    "jpeg",
    "png",
    "gif",
    "webp"
  ],
  "authorized_attachment_extensions": []
  1. Click Save.
    Root Cause Analysis:
    The issue occurs because the API endpoint /answer/api/v1/siteinfo returns null for extension lists instead of an empty array [] after a fresh upgrade.

API Response (Error State):

{
  "site_advanced": {
    "max_image_size": 0,
    "max_attachment_size": 0,
    "max_image_megapixel": 0,
    "authorized_image_extensions": null,
    "authorized_attachment_extensions": null
  }
}

API Response (After Workaround):

{
  "site_advanced": {
    "max_image_size": 0,
    "max_attachment_size": 0,
    "max_image_megapixel": 0,
    "authorized_image_extensions": [],
    "authorized_attachment_extensions": []
  }
}

Code Analysis:
The error is triggered in src/components/Editor/hooks/useImageUpload.ts. The code attempts to check authorized_attachment_extensions.length > 0. Since the value is null, accessing the .length property throws the exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions