fix: stream custom map imports from disk when the file supports it#197
Open
gmaclennan wants to merge 1 commit into
Open
fix: stream custom map imports from disk when the file supports it#197gmaclennan wants to merge 1 commit into
gmaclennan wants to merge 1 commit into
Conversation
Importing a custom map via useImportCustomMapFile uploaded the file with fetch, which on React Native (expo/fetch) reads the whole request body into memory before sending - large SMP files could exhaust memory. Add an uploadFile method to the map server API that uses the file's own upload method when it has one (e.g. expo-file-system's File.upload(), which streams the file from disk on both Android and iOS) and falls back to the existing fetch PUT otherwise, so web and electron are unaffected. Non-2xx upload responses are normalized to the same HTTPError thrown by the fetch path.
achou11
self-requested a review
July 23, 2026 17:04
achou11
approved these changes
Jul 23, 2026
achou11
left a comment
Member
There was a problem hiding this comment.
Couple of non-blocking comments but otherwise lgtm
| // import function we accept an object with the compatible properties and | ||
| // methods, and for the expo File, which can represent a file that does not yet | ||
| // exists, we type the `exists` property so that we can check that. | ||
| export type CompatFile = Omit<File, 'lastModified' | 'webkitRelativePath'> |
Member
There was a problem hiding this comment.
not necessary to export this type right now
Suggested change
| export type CompatFile = Omit<File, 'lastModified' | 'webkitRelativePath'> | |
| type CompatFile = Omit<File, 'lastModified' | 'webkitRelativePath'> |
| } | ||
|
|
||
| type ExpoFileWithUpload = ExpoFileDuckType & { | ||
| upload( |
Member
There was a problem hiding this comment.
just noting that File.upload was added to Expo FileSystem in SDK 56:
https://docs.expo.dev/versions/v56.0.0/sdk/filesystem/#uploadurl-options
Comment on lines
+42
to
+46
| options?: { | ||
| headers?: Record<string, string> | ||
| httpMethod?: string | ||
| sessionType?: 'background' | 'foreground' | ||
| }, |
Member
There was a problem hiding this comment.
just checking: none of the other options are relevant to us?
https://docs.expo.dev/versions/v56.0.0/sdk/filesystem/#uploadoptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
useImportCustomMapFile()uploads the map file withfetch. On React Native the injectedexpo/fetchimplementation reads the whole request body into memory before sending (normalizeBodyInitAsyncconverts any Blob-shaped body, including an expo-file-systemFile, to aUint8Array— still the case in SDK 56). Large SMP files can exhaust memory, which is why comapeo-mobile currently carries a patch toexpo/fetchadding native file streaming. That patch is Android-only and has to be rebased on every SDK upgrade.Solution
expo-file-system's
File.upload()streams the file from disk on both platforms (OkHttpRequestBodystreaming from anInputStreamon Android,URLSession.uploadTask(fromFile:)on iOS), so we can use it instead of fetch when it's available.This adds an
uploadFilemethod to the internal map server API which duck-types the file: if it has anuploadmethod it is called with the resolved URL (httpMethod: 'PUT', andsessionType: 'foreground', since an iOS background session can't reach the in-process map server across app suspension); otherwise it falls back to the existing fetchPUT, so web and electron are unaffected (browser fetch already streamsFilebodies from disk). The mutation keeps its existing contract: it resolves with aResponseand rejects with anHTTPError(error details parsed from a JSON body when available) on non-2xx responses.With this, comapeo-mobile can drop its
expo/fetchpatch entirely.