CodeGenieApp / CodeGenieApp/serverless-express
Error: write EOF
- Dominant language
- JavaScript
- Stars
- 5.3k
- Forks
- 676
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I'm developing a Rest API with Nest.js. I successfully converted it to a monolithic lambda with _aws-serverless-express_ with the next code:
```js
const binaryMimeTypes: string[] = ['application/octet-stream'];
let cachedServer: Server;
async function bootstrapServer(): Promise {
if (!cachedServer) {
const expressApp = express();
const nestApp = await NestFactory.create(
AppModule,
new ExpressAdapter(expressApp)
);
nestApp.use(eventContext());
nestApp.enableCors();
await nestApp.init();
cachedServer = createServer(expressApp, undefined, binaryMimeTypes);
}
return cachedServer;
}
export const handler: Handler = async (
event: APIGatewayEvent,
context: Context
) => {
cachedServer = await bootstrapServer();
return proxy(cachedServer, event, context, 'PROMISE').promise;
};
```
For development, I use _serverless-offline_ and _serverless-webpack_.
When I try to send an image with _multipart/form-data_ to the /upload controller, it throws me an error regardless of the image type. ** With other file types (like .txt or .env) it works as expected. Before moving the app to lambda, it worked without any issues.
Controller:
```js
@Post('upload')
@UseInterceptors(AnyFilesInterceptor())
async upload(@UploadedFiles() files: any) {
console.log('photos', files);
}
```
Sending text file:
```
files [ { fieldname: 'file',
originalname: 'expretiments.js',
encoding: '7bit',
mimetype: 'application/javascript',
buffer:
,
size: 8537 } ]
```
Error log (sending .png):
```
[Nest] 8276 - 09/20/2019, 12:18:42 PM [ExceptionsHandler] Unexpected end of multipart data +149ms
Error: Unexpected end of multipart data
at D:\web\_projects\new-book-2-wheel\server\node_modules\dicer\lib\Dicer.js:62:28
at process._tickCallback (internal/process/next_tick.js:61:11)
ERROR: aws-serverless-express connection error
{ Error: write EOF
at WriteWrap.afterWrite (net.js:788:14) errno: 'EOF', code: 'EOF', syscall: 'write' }
```
What I tried:
- changing multer to express-form-data
- playing around with binaryMimeTypes passed to createServer()
- using aws-lambda-multipart-parser package
aws-serverless-express: **3.3.6**
nodejs: **v10.16.0**
Current workaround: send images in base64 format
Contributor guide
Assessment
This issue has not been assessed yet.