Hi Adam,
I'm adding files upload and download to my API build with Taffy.
For the upload everything is working fine. I've created an endpoint /documents to with the files are sent with a POST. This is OK and works as a charm.
For the download, I'm facing an issue. I've created an endpoint /documents/{filename} with a GET method that get the content of the specified filename (e.g. /documents/mypicture.png) from an external store as a binary object and transfer that binary content to the client using the method streamBinary() and withMime() from the resource.cfc. When I use this, Taffy is throwing me an error: "400 Requested mime type is not supported (png)".
I know that by adding a method "getAsPng" to the my representation class I could bypass this problem but I don't see myself enumerating all possible file extensions... And this method "getAsPng" would even not be used in this case because with streamBinary() doesn't call this method; this method only called with representationOf().
I was thinking of changing code in this way:
- Remove the check on the mime type upfront and let Taffy call the resource.
- Based on the result returned by the resource:
- In case of representationOf(): check the mime type at the moment and throw an error if the mimetype is not supported (no "getAs..." method).
- In case of streamFile(), streamBinary(), streamImage(): check the mime type against the value set by the withMime() and throw an error if not the same.
What do you think?
Do you have another way to do this?
Thanks.
Jean-Bernard