Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to upload a file via Google Cloud Function #652

Open
irfanyppc opened this issue Jun 10, 2022 · 0 comments
Open

Error when trying to upload a file via Google Cloud Function #652

irfanyppc opened this issue Jun 10, 2022 · 0 comments

Comments

@irfanyppc
Copy link

irfanyppc commented Jun 10, 2022

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 file=@test.txt

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant