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