Skip to content

Android/iOS - The image attachment is not cached on Android and iOS devices #85604

Closed

Description

@vincdargento

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: v9.3.39-1
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #65321
Email or phone of affected tester (no customers): N/A
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Android 13 / Xiaomi Poco F5, iOS 15.8.3 / iPhone 7 Plus
App Component: Other

Action Performed:

  1. Open the App
  2. Go to any chat
  3. Upload a single or multiple attachment files
  4. On Android, go to root/android/data/org.me.mobiexpensifyg and try to find the cached image file
  5. On iOS, go to On My iPhone/Expensify and try to find the cached image file

Expected Result:

The image attachment cache file can be found in the local folder of Android and iOS devices

Actual Result:

The image attachment is not cached on Android and iOS devices
Note:

  • On Android, the Expensify folder (root/android/data/org.me.mobiexpensifyg) exists, but there is no image cached file
  • On iOS, the Expensify folder (On My iPhone/Expensify) exists, but there is no image cached file

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

bug.mp4
bug2.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @NJ-2020

Activity

  1. added
    DeployBlockerCash
    Daily
    Bug
    on Mar 17, 2026
  2. melvin-bot commented on Mar 17, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #65321

  3. melvin-bot commented on Mar 17, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. github-actions commented on Mar 17, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  5. OSBotify commented on Mar 17, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #65321 - "(1/2) Implement store/caching for attachments" by @NJ-2020 (High confidence)
    Related Issues: None

    Recommendation: REVERT

    The PR attempts to cache attachment files to a directory that is never created, causing all file caching operations to fail silently on native platforms.

    Labels: Keeping DeployBlockerCash (blocks App deploy). This is a frontend bug in the App repository.

    📋 Detailed Analysis

    Evidence

    The issue was introduced in PR #65321, which adds attachment caching functionality. The PR was merged on 2026-03-16 and is included in the current staging deploy (v9.3.39-1). The bug is only reproducible on staging (where the PR exists) and affects both Android and iOS native apps.

    Verification

    The PR modifies the attachment handling code and adds new files:

    • src/libs/actions/Attachment/index.native.ts - Native attachment caching implementation
    • src/libs/CacheAPI/index.native.ts - Cache API stub for native

    Key file affected: src/libs/actions/Attachment/index.native.ts

    Line 10 defines: const ATTACHMENT_DIR = \${RNFS.DocumentDirectoryPath}/attachments`;`

    Lines 22 and 56 attempt to write files to this directory:

    • Line 22: await RNFS.copyFile(uri, destPath); - Copies uploaded files
    • Line 56: await RNFetchBlob.config({path: filePath}).fetch('GET', uri); - Downloads remote files

    Root Cause

    The attachments directory is never created before attempting to save files to it.

    When RNFS.copyFile() or RNFetchBlob.config({path}) try to write to a non-existent directory, the operations fail. The errors are caught and logged as warnings (lines 28 and 64), but the files are never actually cached.

    This is different from the existing iOS file download implementation (src/libs/fileDownload/index.ios.ts line 69), which properly creates the directory first:

    return RNFS.mkdir(expensifyDir).then(() => {
        return RNFS.writeFile(localPath, fileData, 'utf8')

    The fix would require adding RNFS.mkdir(ATTACHMENT_DIR, {intermediates: true}) before attempting to write files, similar to the iOS download pattern.

  6. MelvinBot commented on Mar 17, 2026

    @MelvinBot
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Image attachments uploaded in chat are not being cached on Android and iOS devices. After uploading a single or multiple attachment files, no cached image files can be found in the device's local storage.

    What is the root cause of that problem?

    The attachments subdirectory under RNFS.DocumentDirectoryPath is never created before the code attempts to write files to it.

    In src/libs/actions/Attachment/index.native.ts:10, ATTACHMENT_DIR is defined as:

    const ATTACHMENT_DIR = `${RNFS.DocumentDirectoryPath}/attachments`;
    

    But RNFS.mkdir(ATTACHMENT_DIR) is never called anywhere in the codebase. When cacheAttachment runs:

    • For local file uploads (line ~22): RNFS.copyFile(uri, destPath) throws because the destination directory doesn't exist
    • For remote URLs (line ~56): RNFetchBlob.config({path: filePath}).fetch('GET', uri) also fails for the same reason

    Both failures are silently swallowed by catch blocks that only call Log.warn('[AttachmentCache] Failed to cache attachment', {error}). Since the Onyx.set() call is inside the try block after the failing write, the Onyx record is never created either — so the system has no record that caching was even attempted.

    For comparison, the iOS file download code at src/libs/fileDownload/index.ios.ts:67-69 correctly calls RNFS.mkdir(expensifyDir) before writing files — the attachment caching code does not follow this pattern.

    What changes do you think we should make in order to solve the problem?

    Add await RNFS.mkdir(ATTACHMENT_DIR) at the top of the cacheAttachment function in src/libs/actions/Attachment/index.native.ts, before any file write operations. RNFS.mkdir() is a no-op if the directory already exists, so it's safe to call every time.

    What alternative solutions did you explore? (Optional)

    • Create directory at app startup: Could add the mkdir call in platform setup, but lazy creation before each write is the pattern used elsewhere in the codebase (e.g., index.ios.ts) and is simpler.
    • Create directory once with a flag: Could track whether the directory was created with a module-level boolean, but RNFS.mkdir is already idempotent so this adds complexity with no benefit.

    Note: PR #85588 "(2/2): Add preview caching logic" is currently open and will wire up getCachedAttachment for display. The write-side fix (this bug) should be addressed in the (1/2) PR scope since the cache files need to exist before (2/2) can read them.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  7. removed
    DeployBlockerCash
    Hourly
    on Mar 17, 2026
  8. 18 remaining items

  9. NJ-2020 commented on May 7, 2026

    @NJ-2020
    Contributor

    Not overdue

  10. added and removed
    Weekly
    on Jun 1, 2026
  11. melvin-bot commented on Jun 1, 2026

    @melvin-bot

    This issue has not been updated in over 15 days. @Julesssss, @NJ-2020 eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  12. added
    Reviewing
    Weekly
    and removed on Aug 13, 2026
  13. added and removed
    Weekly
    on Sep 7, 2026
  14. melvin-bot commented on Sep 7, 2026

    @melvin-bot

    This issue has not been updated in over 15 days. @Julesssss, @NJ-2020 eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  15. melvin-bot commented on Nov 4, 2026

    @melvin-bot

    @Julesssss, @NJ-2020, this Monthly task hasn't been acted upon in 6 weeks; closing.

    If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugEngineeringMonthlyNot a priorityReviewing

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions