Request processed on POST but fails on PATCH

#1

I am using this code to upload an image (direct streaming into the database):

request.multipart.file('file', {}, async function(file) {                                                                                    
  const fileContent = await getStream.buffer(file.stream)                                                                                    
  photo.filecontents = fileContent                                                                                                           
  photo.type = `${file.type}/${file.subtype}`                                                                                                
})                                                                                                                                          
await request.multipart.process()

This works perfectly fine when on a POST HTTP request in MyController.store() method.
However, on a PATCH HTTP request, the request always fails to process (I get a 500 HTTP code on the client side) in MyController.update().

I spent one hour debugging this, the PATCH request reaches the server, everything works except when I un-comment await request.multipart.process().

If I leave only this in the update() method of my controller, the request fails to process also:

request.multipart.field((name, value) => {                                                                                                   
  product.name= value                                                                                                                        
})                                                                                                                                          

Did I set the correct headers on my PATCH request? Yes, the same as I did for POST.

The request also fails to process on PATCH but runs smoothly on POST

Any hints as why this is not working?

0 Likes

#2

Hi @virk Could you give me a hint where to investigate?
This is weird to me. I run the same code several times on isolated proof of concept projects and I had no issue except in this same project.

0 Likes

#3

Hello @begueradj
can you post the content of your routes file?

0 Likes

#4

The route is there. Everything else work in MyConroller.update() if I comment out this single line await request.multipart.process() (I can console.log(params.id) for instance)

0 Likes

#5

@begueradj You said you receive a 500, which means it is a server error. Can you share the error response body that you receive?

0 Likes

#7

try to put the code into a try/catch block to catch the error and see what it is

1 Like

#8

The issue was a typo in the entry I set in processManually array.

0 Likes