-
-
Save mccraigmccraig/e1f06fc113dd6d86507f758fbd7e0562 to your computer and use it in GitHub Desktop.
This file contains 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
(def org-user-files-resource-spec | |
{:methods | |
{:post | |
{:parameters {:path {:org-id s/Uuid | |
:org-user-id s/Uuid} | |
:body {:file er_api.service.resources.tempfile.TempfilePartial | |
(s/optional-key :context) (s/maybe s/Str)}} | |
:coercion-matchers | |
{:body tmpf/tempfile-part-coercion-matchers} | |
:consumes #{"multipart/form-data"} | |
:part-consumer (tmpf/->TempfilePartConsumer) | |
:produces #{"application/json"} | |
:summary "upload a file for an org-user"}} | |
:access-control {:allow-origin #{"*"} | |
:allow-headers ["Authorization" "Content-Type"] | |
:allow-methods #{:post :get}}}) | |
;; new async yada resource | |
(specs/defresource org-user-files-resource | |
[filestore cassandra generate-string] | |
:spec org-user-files-resource-spec | |
:post | |
(fn [{:keys [request parameters] :as ctx}] | |
(info ["file-upload parameters" parameters]) | |
(with-context deferred-context | |
(mlet | |
[:let | |
[auth-user-id (get-in request [:identity :user-id]) | |
{:keys [org-id org-user-id]} (:path parameters) | |
{:keys [filename content-type f] | |
:as tempfile} (get-in parameters [:body :file]) | |
_ (info ["file-upload" {:user-id auth-user-id | |
:org org-id | |
:org-user-id org-user-id | |
:context (get-in request [:params :context]) | |
:tempfile tempfile}])] | |
uploaded-path (filestore/store-org-user-file | |
filestore | |
{:org-id org-id | |
:user-id org-user-id | |
:filename filename | |
:content-type content-type | |
:value f})] | |
(log-action {:session cassandra :org org-id :user auth-user-id | |
:action-key :org-user-files | |
:detail {:org-user-id org-user-id | |
:size (some-> f .length)}}) | |
(return | |
(generate-string | |
uploaded-path)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment