Skip to content
Snippets Groups Projects
Commit ea60f3db1ab2 authored by Arnaud Vergnet's avatar Arnaud Vergnet :sun_with_face:
Browse files

feat: return files as b64 in rql requests

parent d267ebcc88d2
No related branches found
No related tags found
1 merge request!52feat: add routes to upload and download binaries
......@@ -26,6 +26,8 @@
from cubicweb_api.exceptions import ApiException
from cubicweb_api.util import get_api_path_prefix
from cubicweb import Binary
import base64
def datetime_adapter(obj: Union[datetime, date, time], request):
......@@ -38,6 +40,10 @@
return obj.isoformat()
def binary_adapter(binary: Binary, request):
return base64.b64encode(binary.read()).decode("ascii")
def api_exception_view_deriver(view, info: IViewDeriverInfo):
if info.options.get("use_api_exceptions"):
......@@ -57,6 +63,7 @@
json_renderer.add_adapter(datetime, datetime_adapter)
json_renderer.add_adapter(date, datetime_adapter)
json_renderer.add_adapter(time, datetime_adapter)
json_renderer.add_adapter(Binary, binary_adapter)
api_exception_view_deriver.options = ("use_api_exceptions",)
config.add_view_deriver(api_exception_view_deriver)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment