Skip to content

Expose GridFSFile through [Reactive]GridFsResource [DATAMONGO-2240] #3068

Closed
@spring-projects-issues

Description

@spring-projects-issues

Juergen Zimmermann opened DATAMONGO-2240 and commented

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
}

Affects: 2.2 M2 (Moore)

Referenced from: pull request #741

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions