Hapi 17 multipart not working
See original GitHub issueI use Apollo on top of Hapi 17 and I can’t find a way to make file upload work in my project so I made a simple example based on documentation and find out that it’s not working either. Here’s the repository for reproduction of the bug: https://github.com/D34THWINGS/test-hapi-apollo-upload
From what i’ve found so far, Hapi has not yet processed the request when onRequest
extension endpoint is called. So the request.mime
is null
and the processFileUploads
is therefore not called (ref ApolloServer.ts#L20)
I then tried some modifications:
- Moving to
onPreHandler
extension point. This make themime.type
set tomultipart/form-data
and making us going further but still not working. - Passing
request.raw.req
toprocessFileUploads
. This allows the code to make it further but this time the request hangs forever and I can’t seem to find why.
EDIT: Also tried the following:
- Use
request.headers.slice(0, 19)
instead ofrequest.mime
- Passing
request.raw.req
toprocessFileUploads
. But now throws:Cannot assign to read only property 'payload'
because Hapi is later trying to modify payload which has been marked as read only property withinhandleFileUploads
.
EDIT 2: After making some extensive changes to the lib I found out that the parsing of the payload should be disabled for ‘POST’ on the /graphql
route so the apollo-upload-server
can do it’s own parsing. But I think it should be better to have an implementation for Hapi that we should call within the request handler.
So if anyone with a better understanding can help me going through this, I would be happy to make a PR.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:8 (1 by maintainers)
Top GitHub Comments
I am running into this issue big time as well, I did however get it to work by dynamically turning on and off payload parsing in combination with manual parsing for file uploads.
Glad to hear that workaround does the job. Closing this issue because we won’t be directly maintaining integrations with specific frameworks in Apollo Server 3.