alihammad
Next.js file attachment
Here's the function for inserting a product for example:
"use server";
import { getXataClient } from "./xata";
import { XataFile } from "@xata.io/client"; // Generated with CLI
const xata = getXataClient();
export default async function addProduct(data) {
await xata.db.products.create({
...data,
store: process.env.STORE_ID,
photos: [XataFile.fromBase64("SGVsbG8gV29ybGQ=")],
});
}
21 replies
Next.js file attachment
Sure, XataFile.fromBase64 accepts base64 string, but the XataFile can't recognize the name and the type of the file.
Also, the base64Content key in XataFile object is empty.
So it saves empty data of the file to the server.
21 replies
Next.js file attachment
I got it, there's no need to use XataFile as recommended in the Code snippets.
Instead, I used it as recommended in the documentation like this:
{
"name": "sample.png",
"mediaType": "image/png",
"base64Content": "iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAEklEQVR42mNk+M9QzwAEjDAGACCDAv8cI7IoAAAAAElFTkSuQmCC"
}
21 replies