more blobbing
Some checks failed
Publish Ranger template to Laconic Registry / laconic_publish (push) Failing after 1m2s

This commit is contained in:
zramsay 2025-02-02 14:26:06 -05:00
parent 2520ad601d
commit 4e5b894998
2 changed files with 21 additions and 4 deletions

View File

@ -15,8 +15,22 @@ const Page: React.FC = (): React.ReactElement => {
const handleImageAnalysis = () => {
return async (imageFile: File): Promise<VisionAnalysisResult> => {
return analyzeImage(imageFile)
const reader = new FileReader();
return new Promise((resolve, reject) => {
reader.onload = async (event) => {
try {
const arrayBuffer = event.target.result as ArrayBuffer;
const buffer = Buffer.from(arrayBuffer);
const filename = imageFile.name;
const result = await analyzeImage(buffer, filename);
resolve(result);
} catch (error) {
reject(error);
}
};
reader.onerror = (error) => reject(error);
reader.readAsArrayBuffer(imageFile);
});
}
}

View File

@ -21,10 +21,13 @@ export const VISION_CONFIG: VisionConfig = {
description: "Upload photos of " + APP_CONFIG.description + " in " + APP_CONFIG.location + " to help with conservation research.",
}
export async function analyzeImage(imageFile: File): Promise<VisionAnalysisResult> {
export async function analyzeImage(imageBuffer: Buffer, filename: string): Promise<VisionAnalysisResult> {
try {
const formData = new FormData()
formData.append('image', imageFile)
// Create file from buffer using Blob
const blob = new Blob([imageBuffer], { type: 'image/jpeg' })
formData.append('image', blob, filename)
const response = await fetch('/api/analyze', {
method: 'POST',