-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow manually specifying media type. #233
base: master
Are you sure you want to change the base?
Conversation
This looks good to me, but I don’t have a lot of Python experience. It will definitely solve a problem for generating LSST light curves from JSON strings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not comfortable with an unchecked manual override of the MIME type. I feel this might create as many issues (as result of incorrect MIME type driving blob and media entry creation) as it solves.
Override would be acceptable if MIME type is validated, perhaps against a list of known & supported MIME types. That list might also be useful as part of a manual extension-to-MIME mapping solution that could replace current difficult-to-install libmagic
MIME-typing solution.
Somewhat related to that, I’ve made a start on models to validate JSON files in JS. The models here will error if you pass them an invalid JSON-encoded string. |
I've got a slightly different use case than the original issue here, so maybe this should be a new issue: my subjects are dynamically generated strings, not files on disk. At the moment, I'm generating the strings (in Python), writing them to files on disk, then looping back through those file paths and uploading them with This is really slow and inefficient. Since I already have each subject's contents stored in a string, it would be really useful if I could use those strings without having to write them to disk, then read them back again. At the moment, I can work around that by doing this: dynamic_subject = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="391" height="391" viewBox="-70.5 -70.5 391 391" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><rect fill="#fff" stroke="#000" x="-70" y="-70" width="390" height="390"/><g opacity="0.8"><rect x="25" y="25" width="200" height="200" fill="lime" stroke-width="4" stroke="pink" /><circle cx="125" cy="125" r="75" fill="orange" /><polyline points="50,150 50,200 200,200 200,100" stroke="red" stroke-width="4" fill="none" /><line x1="50" y1="50" x2="200" y2="200" stroke="blue" stroke-width="4" /></g></svg>'
subject.locations.append('image/xml+svg')
subject._media_files.append(dynamic_subject)
subject.modified_attributes.add('locations') where In my case I've got a new subject with two locations and two functions, one for each location. One function returns a JSON-encoded string, uploaded as |
I believe the API does validate the MIME type against an allowed list, so it will fail if an invalid type is given. Replacing @eatyourgreens It might be worth seeing if |
Thanks! I will take a look. |
This essentially describes my problem. |
Closes #210