Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

API router throwing error with large files #4524

Closed
mihail727 opened this issue Apr 22, 2022 · 1 comment
Closed

API router throwing error with large files #4524

mihail727 opened this issue Apr 22, 2022 · 1 comment

Comments

@mihail727
Copy link

Environment


  • Operating System: Linux
  • Node Version: v16.14.0
  • Nuxt Version: 3.0.0-rc.0-27508091.78fcbcf
  • Package Manager: yarn@1.22.18
  • Builder: vite
  • User Config: runtimeConfig, buildModules, modules, tailwindcss, app, nitro, build, modern
  • Runtime Modules: @nuxtjs/tailwindcss@5.0.3
  • Build Modules: @vueuse/nuxt@8.3.1

Reproduction

https://stackblitz.com/edit/github-tjflbh?file=app.vue

Reproduction does not allow opening files
Therefore, there is only a structure

Describe the bug

When i'm trying to upload from client to server the large file - i'm getting error:

ERROR  [h3] write EPIPE
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16)

Additional context

No response

Logs

No response

@mihail727
Copy link
Author

mihail727 commented Apr 26, 2022

I managed to start uploading large files by using multer and callHanlder:
@/server/api/upload.ts

import { CompatibilityEvent, callHandler } from 'h3';
import multer from 'multer';

const storage = multer.diskStorage({
	destination: (req, file, cb) => {
		cb(null, './');
	},
	filename: (req, file, cb) => {
		cb(null, file.originalname);
	},
});

export default async (event: CompatibilityEvent): Promise<IServerResponse> => {
	await callHandler(multer({ storage }).single('file'), event.req, event.res);
	return { success: true };
};

It turns out all this time it worked just Typescript complains about types:

text:

An argument of type "RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>" cannot be assigned to a parameter of type "Middleware".
   Parameter types "req" and "req" are incompatible.
     The 'IncomingMessage' type is missing the following properties from the 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' type: get, header, accepts, acceptsCharsets and 25.ts(2345) more

@nuxt nuxt locked and limited conversation to collaborators Apr 27, 2022
@danielroe danielroe converted this issue into a discussion Apr 27, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants