Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-2240

Expose GridFSFile through [Reactive]GridFsResource

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 2.2 M2 (Moore)
    • Fix Version/s: 2.2 RC2 (Moore)
    • Component/s: Core
    • Labels:
      None

      Description

      ReactiveGridFsResource has no method to retrieve the value of _contentType or at least metadata. For example in a REST application the response header of a GET request cannot be set to the correct content type.

      My ugly workaround is a Kotlin extension function:

      import com.mongodb.client.gridfs.model.GridFSFile
      import org.springframework.data.mongodb.gridfs.ReactiveGridFsResource
      import org.springframework.util.ReflectionUtils.findField
      import org.springframework.util.ReflectionUtils.getField
      import org.springframework.util.ReflectionUtils.makeAccessible
      
      fun ReactiveGridFsResource.contentType(): String {
        val fileProp = findField(ReactiveGridFsResource::class.java, "file")!!
        makeAccessible(fileProp)
        val file = getField(fileProp, this) as GridFSFile
        return file.metadata?.get("_contentType") as String
      }
      

        Attachments

          Activity

            People

            • Assignee:
              mp911de Mark Paluch
              Reporter:
              juergen.zimmermann Juergen Zimmermann
              Last updater:
              Mark Paluch
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: