1

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! :)

A Bit of Help
  • 1,368
  • 19
  • 36
  • Hi, I'm exactly on the same problem... – Saveriu CIANELLI Oct 31 '19 at 14:21
  • Wow! I thought that there would be some suggestions... One thought that I had was to pass the metadata as parameters rather than in the body... Or even in the header, but, still... This should be doable... I am going to kick it around some more before falling back on these alternatives. – A Bit of Help Nov 01 '19 at 01:51
  • I did some tests too: https://stackoverflow.com/questions/58500409/how-to-upload-mono-of-json-and-flux-of-files-with-webflux Any updates? – Saveriu CIANELLI Nov 05 '19 at 16:44

0 Answers0