Created
August 7, 2013 14:08
-
-
Save axeda/6174381 to your computer and use it in GitHub Desktop.
Download a file from the file store as an embeddable image file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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