fix(share): read the shared file via native Filesystem, not fetch (remote-origin)
Sharing a photo into the app: the "Send to…" picker appeared and staging worked, but picking a chat said "no file found". Cause: the app loads its UI from the REMOTE origin (remote.bizgaze.com), and I read the staged bytes with fetch(convertFileSrc(uri)). Capacitor's local `_capacitor_file_` serving isn't on the remote origin, so that fetch is CORS-blocked / hits the remote server → 404. Read through the native bridge instead: Filesystem.readFile returns base64 in native code, never touching the webview network stack, so it reads the App Group file the app has entitlement access to. Falls back to it.path, then to the old webview path for local-asset builds. Web-only fix — no rebuild. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+20
-5
@@ -1197,7 +1197,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<script src="/icons.js?v=6"></script>
|
||||
<script>window.__BUILD='2026-07-23-batch166';console.log('%cBiz Connect','color:#1F3B73;font-weight:bold','build '+window.__BUILD);
|
||||
<script>window.__BUILD='2026-07-24-batch167';console.log('%cBiz Connect','color:#1F3B73;font-weight:bold','build '+window.__BUILD);
|
||||
// Emoji are rendered with the OS's own (colour) emoji font — instant, zero network.
|
||||
//
|
||||
// We used to run Twemoji over every emoji, which swapped each one for an <img> pulled INDIVIDUALLY from
|
||||
@@ -3551,13 +3551,28 @@ function bzUploadBlob(file, onPct){
|
||||
xhr.send(file);
|
||||
});
|
||||
}
|
||||
function bzB64ToBlob(b64, mime){
|
||||
const bin=atob(b64||''), len=bin.length, u8=new Uint8Array(len);
|
||||
for(let i=0;i<len;i++) u8[i]=bin.charCodeAt(i);
|
||||
return new Blob([u8], { type: mime||'application/octet-stream' });
|
||||
}
|
||||
async function bzShareItemToFile(it){
|
||||
// Pull the staged file's bytes into a File the upload endpoint accepts. convertFileSrc turns the
|
||||
// App Group file:// URI into something the WebView can fetch.
|
||||
// Read the staged file's bytes for upload. We MUST go through the native Filesystem bridge, NOT
|
||||
// fetch(convertFileSrc(...)): this app loads its UI from the REMOTE origin (remote.bizgaze.com), so
|
||||
// Capacitor's local `_capacitor_file_` serving isn't on this origin — a fetch there is CORS-blocked or
|
||||
// hits the remote server (404 "not found"). Filesystem.readFile reads the file in native code and
|
||||
// returns base64, bypassing the webview network stack entirely.
|
||||
const Fs=window.Capacitor&&window.Capacitor.Plugins&&window.Capacitor.Plugins.Filesystem;
|
||||
if(Fs&&Fs.readFile){
|
||||
let r=null;
|
||||
try{ r=await Fs.readFile({ path: it.uri }); } // full file:// path, no directory
|
||||
catch(e){ try{ r=await Fs.readFile({ path: it.path }); }catch(e2){ throw new Error('Could not read the shared file'); } }
|
||||
return new File([bzB64ToBlob((r&&r.data)||'', it.mime)], it.name||'file', { type: it.mime||'application/octet-stream' });
|
||||
}
|
||||
// Fallback (local-asset builds only): the webview file scheme.
|
||||
const src=window.Capacitor.convertFileSrc(it.uri);
|
||||
const res=await fetch(src); if(!res.ok) throw new Error('read failed');
|
||||
const blob=await res.blob();
|
||||
return new File([blob], it.name||'file', { type: it.mime||blob.type||'application/octet-stream' });
|
||||
return new File([await res.blob()], it.name||'file', { type: it.mime||'application/octet-stream' });
|
||||
}
|
||||
function openSharePicker(items){
|
||||
const files=items.filter(i=>i.kind==='file');
|
||||
|
||||
Reference in New Issue
Block a user