How to implement @RequestPart in a reactive, functional (not annotated) webflux service?

别说谁变了你拦得住时间么 提交于 2020-08-09 08:15:17

问题


I have a Spring Boot 2, reactive webflux web service, which persists uploaded, multipart fileparts to MongoDB's GridFS. This is working properly. Today, a request was made to include metadata for the files being added to GridFS. Unfortunately, I have not been able to get it to work with my functional/non-annotated web service. I would appreciate any suggestions or nudges in the correct direction. Here are the details:

An example of the request being sent to my endpoint:

curl -X "POST" "http://localhost:8080/api/maps" \
     -H 'Content-Type: multipart/form-data; charset=utf-8; boundary=__X_BOUNDARY__'"'"'' \
     -F "files=@animage.jpg" \
     -F "metadata={\"tenantId\":\"598b53702f52f9\",\"projectId\":\"59c0a78d6212dc\"}

Here is my current service that works without the metadata in the request, above:

    override fun upload(fluxFileParts: Flux<FilePart>): Flux<Map<String, String>> =

        fluxFileParts
            .flatMap { filePart ->
                reactiveGridFsTemplate.store(
                    filePart.content(),
                    filePart.filename(),
                    kMediaTypeMap.getValue(filePart.filename().getFileExtension())
                )
                    .map { objectId ->
                        mapOf("objectId" to objectId.toHexString())
                    }
            }

Basically, I am trying to be able to implement something like the following. If I were using annotations, the @RequestPart would provide the strongly typed object.

override fun uploadWithProjectMetadata(
        fluxFileParts: Flux<FilePart>,
        metadata: SliderUploadMetadata
        //@RequestPart("files") fluxFileParts: Flux<FilePart>,
        //@RequestPart metadata: SliderUploadMetadata
    ): Flux<Map<String, String>>

I'd appreciate your help... I have been going around and around for several hours and am not making any progress... Arggg... frustrating! :)

来源:https://stackoverflow.com/questions/58639183/how-to-implement-requestpart-in-a-reactive-functional-not-annotated-webflux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!