如何在黑色中接受文件上传

发布于 2025-01-03 16:02:16 字数 331 浏览 4 评论 0原文

我有一个像这样的文件输入设置

[:p "Upload a book"]
      (form-to [:post "/upload"]
               (file-upload :book)
               (submit-button "Upload"))

我的上传端点看起来像这样。

(defpage [:post "/upload"] {:keys [book]} (println book))

book 似乎只是上传的文件标题的字符串,而不是文件本身。我如何获取该文件?

I have a file input setup like this

[:p "Upload a book"]
      (form-to [:post "/upload"]
               (file-upload :book)
               (submit-button "Upload"))

My upload endpoint then looks like this.

(defpage [:post "/upload"] {:keys [book]} (println book))

book just seems to be a string of the title of the file that was uploaded and not the file itself. How do I get the file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

穿透光 2025-01-10 16:02:16

根据此帖子(请参阅 Chris Granger 的第二篇文章):

您可以使用以下内容:

(defpage [:post "upload"] {:keys [myFile]}
  (println myFile) ;; see all the things the file contains
  (io/copy (io/file (:tempfile myFile)) (io/file "uploads/some-new-name"))) 

这是此线程的要点:

带有注释(再次来自 Chris )您需要 Leiningen 1.6.1.1+ 才不会遇到错误。

您可以在此处看到类似的内容(尽管对于 Amazon S3):

希望这会有所帮助。

According to this thread (see second post by Chris Granger):

you can use something like:

(defpage [:post "upload"] {:keys [myFile]}
  (println myFile) ;; see all the things the file contains
  (io/copy (io/file (:tempfile myFile)) (io/file "uploads/some-new-name"))) 

Here's a gist from this thread:

with a note (again from Chris) that you need Leiningen 1.6.1.1+ not to run into a bug.

You can see a similar thing (though for Amazon S3) here:

Hope this helps.

℡寂寞咖啡 2025-01-10 16:02:16

我认为你接受罚款;我相信您发帖错误。尝试 form-to {:enctype "multipart/form-data"},或从 shell curl --form book=@/home/me/Penguins.jpg http://localhost :8080/上传

I think you're accepting fine; I believe you're posting wrong. Try form-to {:enctype "multipart/form-data"}, or from the shell curl --form book=@/home/me/Penguins.jpg http://localhost:8080/Upload

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文