By "application" I mean "Ring handler". Your request looks wrong. The boundary you set in your header (------BoUnDaRyFFFFFF) doesn't match the boundary I see in the body (--2n639DJeu...).
- James On 7 July 2016 at 05:29, <aaarturoz...@gmail.com> wrote: > The request header: > > > > <https://lh3.googleusercontent.com/-zl6jkFm15Pc/V33X-i2KFzI/AAAAAAAAAAM/c5zfE6Vn8qEHIZ3EInJed3HhKaFlFaINACLcB/s1600/%25E5%25B1%258F%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7%2B2016-07-07%2B12.11.55.png> > > The request body: > > > <https://lh3.googleusercontent.com/-1Kca-9uDPeI/V33Ye1MImfI/AAAAAAAAAAQ/SyACY6OPidcw8Z3s42XYKEu9OyGb6-HNQCLcB/s1600/%25E5%25B1%258F%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7%2B2016-07-07%2B12.15.19.png> > > My test params are: > > String[] tags = {"aaaa", "bbbb", "cccc"}; > s = test.upload("/Users/apple/test.txt", tags, "19960808", > "qwertyuiopasdfghjklzxcvbnm"); > > > The content of test.txt is "This is a test...". > > > Is there anything wrong? > > > BTW, could you give me an example of the definition of app? I'm not sure > which one is correct. > > > 在 2016年7月7日星期四 UTC+8上午10:30:31,James Reeves写道: >> >> In all your examples except for possibly the last, you have the multipart >> middleware added twice over to your application. >> >> Also, are you sure it's not a problem with your client code? >> >> One thing to try is recording your HTTP request by pointing your client >> at a netcat listener (e.g. "nc -l 3000"). Or writing a handler that dumps >> out the headers and the contents of the request body. >> >> - James >> >> On 7 July 2016 at 03:18, <aaartu...@gmail.com> wrote: >> >>> This is the link to the question in stackoverflow: >>> >>> http://stackoverflow.com/questions/38226276/cant-extract-multipart-params-from-post-request-in-compojure >>> >>> 在 2016年7月7日星期四 UTC+8上午10:13:25,aaartu...@gmail.com写道: >>> >>>> When I try to extract the multipart-params from a POST request like >>>> this: >>>> >>>> (defroutes upload-routes >>>> (POST "/upload" {params :params} (println params)) >>>> >>>> >>>> I got {}. >>>> >>>> Then I tried like this: >>>> >>>> (defroutes upload-routes >>>> (POST "/upload" {multipart-params :multipart-params} (println >>>> multipart-params)) >>>> >>>> I still got {}. >>>> >>>> I guess there are something wrong about my middleware. >>>> >>>> So I tried to change the handler, here are the handlers I had tried: >>>> >>>> (ns cloudserver.handler >>>> (:require [compojure.core :refer [defroutes routes]] >>>> [compojure.route :as route] >>>> [compojure.handler :as handler] >>>> [cloudserver.routes.home :refer [home-routes]] >>>> [noir.util.middleware :as noir-middleware] >>>> [cloudserver.routes.auth :refer [auth-routes]] >>>> [cloudserver.routes.upload :refer [upload-routes]] >>>> [cloudserver.routes.search :refer [search-routes]] >>>> [cloudserver.routes.download :refer [download-routes]] >>>> [ring.middleware.defaults :refer [api-defaults wrap-defaults >>>> site-defaults]] >>>> [ring.middleware.multipart-params :refer >>>> [wrap-multipart-params]] >>>> [ring.middleware.params :refer [wrap-params]] >>>> [noir.session :as session] >>>> [ring.middleware.session.memory :refer [memory-store]])) >>>> >>>> (def app >>>> (-> >>>> (routes auth-routes >>>> home-routes >>>> upload-routes >>>> search-routes >>>> download-routes >>>> app-routes) >>>> session/wrap-noir-session >>>> (wrap-defaults(assoc-in site-defaults [:security :anti-forgery] false) >>>> wrap-multipart-params >>>> wrap-params)) >>>> (def app >>>> (-> >>>> (routes auth-routes >>>> home-routes >>>> upload-routes >>>> search-routes >>>> download-routes >>>> app-routes) >>>> session/wrap-noir-session >>>> (wrap-defaults(assoc-in site-defaults [:security :anti-forgery] false) >>>> wrap-multipart-params)) >>>> (def app >>>> (-> >>>> (routes auth-routes >>>> home-routes >>>> upload-routes >>>> search-routes >>>> download-routes >>>> app-routes) >>>> session/wrap-noir-session >>>> (wrap-defaults (-> site-defaults >>>> (assoc-in [:security :anti-forgery] false) >>>> (assoc-in [:params :multipart] true) >>>> (assoc-in [:params :nested] true))) >>>> handler/site)) >>>> (def app >>>> (-> >>>> (routes auth-routes >>>> home-routes >>>> upload-routes >>>> search-routes >>>> download-routes >>>> app-routes) >>>> wrap-multipart-params >>>> session/wrap-noir-session >>>> (wrap-defaults(assoc-in site-defaults [:security :anti-forgery] false))) >>>> (def app >>>> (noir-middleware/app-handler >>>> [auth-routes >>>> home-routes >>>> upload-routes >>>> search-routes >>>> download-routes >>>> app-routes] >>>> :ring-defaults (assoc site-defaults :security nil))) >>>> >>>> But the only result I got is {} >>>> ------------------------------ >>>> >>>> My client code is: >>>> >>>> public int upload (String filename, String[] tags, String time, String >>>> fingerprint) throws IOException { >>>> String url = host + "/upload"; >>>> CloseableHttpClient httpClient = >>>> HttpClients.custom().setDefaultCookieStore(cookieStore).build(); >>>> HttpPost httpPost = new HttpPost(url); >>>> >>>> MultipartEntityBuilder mulentity = MultipartEntityBuilder.create(); >>>> >>>> mulentity.addBinaryBody("photo", new File(filename)); >>>> >>>> for (int i = 0; i < tags.length; i ++) { >>>> mulentity.addTextBody("tag" + i, tags[i]); >>>> } >>>> >>>> mulentity.addTextBody("fingerprint", fingerprint); >>>> mulentity.addTextBody("time", time); >>>> mulentity.addTextBody("filename", >>>> filename.substring(filename.lastIndexOf(File.separatorChar) + 1, >>>> filename.length())); >>>> >>>> HttpEntity entity = mulentity.build(); >>>> httpPost.setEntity(entity); >>>> httpPost.setHeader("Content-Type", "multipart/form-data;boundary=" + >>>> BOUNDARY); >>>> >>>> int status = 3; >>>> >>>> try { >>>> ResponseHandler<String> responseHandler = new >>>> BasicResponseHandler(); >>>> String response = httpClient.execute(httpPost, responseHandler); >>>> status = Integer.parseInt(response); >>>> } catch (ClientProtocolException e) { >>>> e.printStackTrace(); >>>> } catch (UnsupportedEncodingException e) { >>>> e.printStackTrace(); >>>> } finally { >>>> httpClient.close(); >>>> } >>>> return status; >>>> } >>>> >>>> ------------------------------ >>>> >>>> I am really a green hand in clojure web programming. Thanks a lot! >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To post to this group, send email to clo...@googlegroups.com >>> Note that posts from new members are moderated - please be patient with >>> your first post. >>> To unsubscribe from this group, send email to >>> clojure+u...@googlegroups.com >>> For more options, visit this group at >>> http://groups.google.com/group/clojure?hl=en >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to clojure+u...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.