Back

[SOLVED] Cannot read properties of undefined (reading 'pipe')

  • 0
  • Self Hosted
  • Web
  • Storage
Marcelo Delta
20 Dec, 2023, 03:39

Hello, I'm having a problem sending a file to Storage. What am I doing wrong?

I tried to do it through the documentation, but without success. Could anyone help? Thanks.

TypeScript
const filePath = Application.tmpPath('uploads', fileName);
await storage.createFile(Env.get('APPWRITE_BUCKET'), ID.unique(), filePath)
TL;DR
Cannot read properties of undefined (reading 'pipe') The error is occurring because the code is trying to upload a folder instead of a file. The solution is to use the InputFile class instead of passing a file path directly. Here is an example of how to use InputFile: ``` const fileName = `${randomUUID()}.${file.extname}`; await file.move(Application.tmpPath('uploads'), { name: fileName }); if (file.state === 'moved') { const inputFile = InputFile.fromPath(Application.tmpPath('uploads'), fileName); await storage.createFile(Env.get('APPWRITE_BUCKET'), ID.unique(), inputFile
Drake
20 Dec, 2023, 04:19

What SDK are you using?

Marcelo Delta
20 Dec, 2023, 04:20

nodejs

Drake
20 Dec, 2023, 04:20

You can't pass a path. You need to use InputPath

Marcelo Delta
20 Dec, 2023, 04:29

I've already tried using the inputFile

However, the error below occurs.

[01:27:49.539] FATAL (intranet/16908): "uncaughtException" detected Error: EISDIR: illegal operation on a directory, read [01:27:49.539] WARN (intranet/16908): pino.final with prettyPrint does not support flushing Error: EISDIR: illegal operation on a directory, read [ warn ] Underlying HTTP server died with "1 code"

Drake
20 Dec, 2023, 04:30

What's your code with input file?

Drake
20 Dec, 2023, 04:32

And based on this error, it sounds like your code is trying to upload a folder rather than a file

Marcelo Delta
20 Dec, 2023, 04:32

Is it because I'm using it on Windows?

if (file) { // Gera um nome aleatório para o arquivo let fileName = ${randomUUID()}.${file.extname}; await file.move(Application.tmpPath('uploads'), { name: fileName }); if (file.state === 'moved') { await storage.createFile(Env.get('APPWRITE_BUCKET'), ID.unique(), InputFile.fromPath(Application.tmpPath('uploads'),fileName)) } return fileName; }

Drake
20 Dec, 2023, 04:33

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

Marcelo Delta
20 Dec, 2023, 04:33

Indeed, he was carrying a briefcase. Now it worked perfectly.

Marcelo Delta
20 Dec, 2023, 04:34

Thanks again @Steven

Drake
20 Dec, 2023, 04:36

[SOLVED] Cannot read properties of undefined (reading 'pipe')

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more