Back
Cannot read properties of undefined (reading 'size') while uploading image to Appwrite
- 0
- Web
- Storage
- REST API

I am trying to upload image to Appwrite but getting above mentioned error
TypeScript
import { ID } from "appwrite";
import storage from "./storage.js";
const addArticleImage = async (image, name) => {
return storage.createFile("<BUCKET_ID>", ID.unique(), image, name);
};
export default addArticleImage;
TypeScript
import addArticleImage from "./appwrite/article_images.js";
import { Readable } from "stream";
const upload = multer({
storage: multer.memoryStorage(),
});
app.post("/api/v1/images", upload.single("image"), async (req, res) => {
try {
console.log(req.file);
res.json({ name: "HE" });
const stream = Readable.from(req.file.buffer);
const img = addArticleImage(stream, req.file.originalname);
console.log(img);
} catch (error) {
console.log(error);
}
});
TL;DR
Developers are encountering an error 'Cannot read properties of undefined (reading 'size')' while trying to upload an image to Appwrite. The issue occurs because req.file.buffer is undefined. To solve this, developers can use multer and Readable from "stream" to create a stream from req.file.buffer and then pass it into addArticleImage function.Recommended threads
- Looking for FullStack Developer
I'm looking for FullStack Developer who is passionated about both Frontend and Backend. If you are interested, please DM me. Thanks.
- Hi im using vvs studio to make a charact...
my game involves magic , leveling up aka "phase" max phase is 30 each 10 20 30 theres awakening 1 2 3 i want to make a character builder so that players can fig...
- Limit File Upload count?
Is there a way to limit the number of files a user can upload? I know there's a limit of file size but in my case I'd like to limit the user to only upload x am...
