micronaut-gcp icon indicating copy to clipboard operation
micronaut-gcp copied to clipboard

Required argument [CompletedFileUpload file] not specified

Open Biazverkhi opened this issue 3 years ago • 2 comments

Hi! I am using GCP (Functions), Maven build, Micronaut 2.5.4 I created a controller with one entry point (code posted below), and running the function locally: mvn clean install function:run

application.yaml is emty

When i send POST request (from Insomnia) localhost:8080/bpmn2?name=testfromquery Multipart->file->resources.zip Header->Content-Type->multipart/form-data i get response:

{ "message": "Required argument [CompletedFileUpload file] not specified", "_links": { "self": { "href": "/bpmn2", "templated": false}}}

Environment Information

  • Operating System: Windows 10
  • Micronaut Version: 2.5.4
  • JDK Version: jdk-11

Example Application

@Controller("/bpmn2)
public class ImportController {

// this service is @Singelton
    private final Importservice;

    public ImportController(ImportService service) {
        this.service = service;
    }

    @Consumes(value = MediaType.MULTIPART_FORM_DATA)
    @Produces(value = MediaType.APPLICATION_JSON)
    @Post
    public HttpResponse<String> importing(CompletedFileUpload file, @QueryValue("name") String projectName) {
        try {
        return HttpResponse.ok(service.getPayload(file.getName(), file.getInputStream(), projectName));
        } catch (Exception e) {
            return HttpResponse.badRequest(e.getMessage());
        }
    }
}

What am I doing wrong?

Biazverkhi avatar May 26 '21 10:05 Biazverkhi

Hey Biazverkhi,

Did you manage to find an answer to this? I am struggling with the same issue, if you have any tips would be greatly appreciated.

Thanks

irfanyppc avatar Jun 10 '22 06:06 irfanyppc

In my case, this issue was caused by a mismatch between the form field name and my variable name in the controller.

You must sync the field names before Micronaut will pick up the file. So, for example, if your controller endpoint looked like this:

@Post(uri = "/test", consumes = MediaType.MULTIPART_FORM_DATA)
public String testEndpointMadeForThisExample(CompletedFileUpload fileUpload) {
    return "success";
}

your form must include the file as a field called fileUpload. You can confirm things are configured correctly by checking the request in your browser tools' Payload tab.

For this example, the correct Payload configuration would be image

wdavis12-chwy avatar Mar 30 '23 16:03 wdavis12-chwy