Skip to content

Instantly share code, notes, and snippets.

@axeda
Created August 7, 2013 14:08
Show Gist options
  • Select an option

  • Save axeda/6174381 to your computer and use it in GitHub Desktop.

Select an option

Save axeda/6174381 to your computer and use it in GitHub Desktop.
Download a file from the file store as an embeddable image file
import static com.axeda.sdk.v2.dsl.Bridges.*
import javax.activation.MimetypesFileTypeMap
import com.axeda.services.v2.*
import com.axeda.sdk.v2.exception.*
import com.axeda.drm.sdk.scripto.Request
def knowntypes = [
[png: 'image/png']
,[gif: 'image/gif']
,[jpg: 'image/jpeg']
]
def params = Request.parameters.size() > 0 ? Request.parameters : parameters
def response = fileInfoBridge.getFileData(params.fileId)
def fileinfo = fileInfoBridge.findById(params.fileId)
def type = fileinfo.filename.substring(fileinfo.filename.indexOf('.') + 1,fileinfo.filename.size())
type = returnType(knowntypes, type)
def contentType = params.type ?: (type ?: 'image/jpg')
return ['Content': response, 'Content-Disposition': contentType, 'Content-Type':contentType]
def returnType(knowntypes, ext){
return knowntypes.find{ it.containsKey(ext) }?."$ext"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment