fix: improve image extension handling and error reporting in upload functions
Some checks failed
Build App / build (push) Failing after 6m56s
Some checks failed
Build App / build (push) Failing after 6m56s
This commit is contained in:
@@ -52,5 +52,5 @@ jobs:
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: android-preview-build.zip
|
||||
path: mobile/app-build/*
|
||||
path: mobile/app-build
|
||||
if-no-files-found: error
|
||||
|
||||
@@ -124,11 +124,16 @@ def main(args):
|
||||
if not image_b64:
|
||||
continue
|
||||
image_bytes = base64.b64decode(image_b64)
|
||||
file_name = f"tv-rotator-{ts}-{idx}.{ext}"
|
||||
MINIO_CLIENT.put_object(
|
||||
BUCKET, file_name, io.BytesIO(image_bytes), len(image_bytes),
|
||||
content_type=f"image/{ext}",
|
||||
)
|
||||
# Normalise ext: strip any URI junk, fall back to jpg
|
||||
safe_ext = ext if ext and len(ext) <= 5 and ext.isalnum() else "jpg"
|
||||
file_name = f"tv-rotator-{ts}-{idx}.{safe_ext}"
|
||||
try:
|
||||
MINIO_CLIENT.put_object(
|
||||
BUCKET, file_name, io.BytesIO(image_bytes), len(image_bytes),
|
||||
content_type=f"image/{safe_ext}",
|
||||
)
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": f"MinIO upload failed: {e}"}
|
||||
public_url = f"https://content2.reversed.dev/{BUCKET}/{file_name}"
|
||||
urls.append(public_url)
|
||||
return {"status": "success", "urls": urls}
|
||||
|
||||
@@ -776,7 +776,7 @@ function ImageRotatorFields({ form, onChange, onUrlsChange }: ImageRotatorFields
|
||||
if (result.canceled) return;
|
||||
const asset = result.assets[0];
|
||||
if (!asset.base64) { Alert.alert("Error", "Could not read image data."); return; }
|
||||
const ext = asset.uri.split(".").pop()?.toLowerCase() ?? "jpg";
|
||||
const ext = (asset.mimeType?.split("/")[1] ?? asset.uri.split(".").pop() ?? "jpg").toLowerCase();
|
||||
setUploading(true);
|
||||
try {
|
||||
const res = await fetch(`${BASE_URL}/push_upload_images`, {
|
||||
|
||||
@@ -63,7 +63,7 @@ export function SettingsPage() {
|
||||
return;
|
||||
}
|
||||
|
||||
const ext = (asset.uri.split(".").pop() ?? "jpg").toLowerCase();
|
||||
const ext = (asset.mimeType?.split("/")[1] ?? asset.uri.split(".").pop() ?? "jpg").toLowerCase();
|
||||
setPendingUri(asset.uri);
|
||||
setPendingBase64(asset.base64 ?? null);
|
||||
setPendingExt(ext);
|
||||
|
||||
Reference in New Issue
Block a user