Trieve provides a simple way to integrate image search into your application. This guide will walk you through the steps to set up image search with Trieve.
For a full implementation example, take a look at the way we implement image search in our search component.
After the user selects an image, you can either upload it to Trieve and get a URL for it or use your own CDN. Here’s how you can do it with Trieve:
Copy
Ask AI
const handleFileUpload = async (selectedFile: File) => { try { // Convert the file to a base64 string const base64 = await convertToBase64(selectedFile); // Upload the file to Trieve and get a unique file ID const fileId = await uploadFile(trieveSDK, selectedFile.name, base64, { create_chunks: false // Set to false to ensure that your file isn't indexed }); // Get a public URL for the uploaded image const imageUrl = await getPresignedUrl(trieveSDK, fileId); return imageUrl; } catch (error) { console.error('Image upload failed:', error); return null; }};