Skip to content

Commit

Permalink
Handle upload of the same image again
Browse files Browse the repository at this point in the history
  • Loading branch information
egli committed Jun 10, 2024
1 parent 9eefa4a commit 99d84df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/clj/daisyproducer2/documents/images.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
;; make sure path exists
(fs/create-dirs (fs/parent absolute-path))
;; copy the contents into the archive
(fs/copy tempfile absolute-path)
(fs/copy tempfile absolute-path {:replace-existing true})
;; and store it in the db ...
(->
(db/insert-image {:document-id document-id :content (str path)})
Expand Down
9 changes: 6 additions & 3 deletions src/clj/daisyproducer2/routes/services.clj
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,12 @@
:handler (fn [{{{:keys [id]} :path {{:keys [filename tempfile]} :file} :multipart} :parameters
{{uid :uid} :user} :identity}]
(try
(let [new-key (images/insert-image id filename tempfile)
new-url (format "/documents/%s/images/%s" id new-key)]
(created new-url {}))
(if-let [new-key (images/insert-image id filename tempfile)]
;; a new image resource was created
(let [new-url (format "/documents/%s/images/%s" id new-key)]
(created new-url {}))
;; an existing image was uploaded again
(no-content))
(finally
(fs/delete tempfile))))}
:delete {:summary "Delete all images of a given document"
Expand Down

0 comments on commit 99d84df

Please sign in to comment.