micronaut-gcp
micronaut-gcp copied to clipboard
Error when trying to upload a file via Google Cloud Function
Issue description
Hi,
I am attempting to upload a file in a Google Cloud Function via a MultiPart Form Data, however getting the following error:
"message": "Required Body [file] not specified",
I have taken the example code from the documentation:
@Controller("/upload")
public class DemoController {
@Post(value = "/completed", consumes = MULTIPART_FORM_DATA, produces = TEXT_PLAIN)
public HttpResponse<String> uploadCompleted(@Body CompletedFileUpload file) {
try {
File tempFile = File.createTempFile(file.getFilename(), "temp");
Path path = Paths.get(tempFile.getAbsolutePath());
Files.write(path, file.getBytes()); //
return HttpResponse.ok("Uploaded");
} catch (IOException e) {
return HttpResponse.badRequest("Upload Failed");
}
}
}
My curl request is:
curl -X POST http://localhost:8080/upload/completed -F [email protected]
I am getting the following error:
"message": "Bad Request",
"_links": {
"self": {
"href": "http://localhost:8080/upload/completed",
"templated": false
}
},
"_embedded": {
"errors": [
{
"message": "Required Body [file] not specified",
"path": "/file"
}
]
}
}
Any tip on how to resolve this would be greatly appreciated.
Many Thanks