Wenn ich versuche, die mehrt-params aus einer POST-Anfrage wie folgt zu extrahieren:Kann nicht mehrt-params von POST-Anfrage in compojure extrahieren
(defroutes upload-routes
(POST "/upload" {params :params} (println params))
Ich habe {}
.
Dann habe ich versucht so:
(defroutes upload-routes
(POST "/upload" {multipart-params :multipart-params} (println multipart-params))
Ich habe noch {}
.
Ich denke, dass etwas an meiner Middleware nicht stimmt.
Also versuchte ich den Handler zu ändern, werden hier die Handler ich versucht hatte:
(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)))
Aber das einzige Ergebnis, das ich ist bekam {}
Mein Client-Code ist:
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;
}
Ich bin wirklich eine grüne Hand in clojure Webprogrammierung. Danke vielmals!
Problem sovled. Das liegt daran, dass die Grenze in der Anfrage falsch ist.
Das Problem besteht darin, dass die Grenze in der Anforderung Header unterscheidet sich von der Grenze im Anfragetext. Trotzdem vielen Dank. – Arturo