mirror of
https://github.com/mito-systems/ranger-app.git
synced 2026-05-05 01:02:04 +00:00
more blobbing
Some checks failed
Publish Ranger template to Laconic Registry / laconic_publish (push) Failing after 1m2s
Some checks failed
Publish Ranger template to Laconic Registry / laconic_publish (push) Failing after 1m2s
This commit is contained in:
parent
2520ad601d
commit
4e5b894998
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user