grails通过MultipartEntity接收文件

时间:2013-06-25 13:00:22

标签: java grails

我使用这个httpclient将图像发布到我的grails,如下所示。我如何收到grails文件?

public static String webPost(String method, File data, Context c) throws Exception {

    String json = "";

    if (isOnline(c) == true) {
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response;
        HttpPost httppost ; 
        try {
            httppost = new HttpPost(method);
            MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            entity.addPart("image", new FileBody(data));
            httppost.setEntity(entity);
            response = httpclient.execute(httppost);

               if (response != null) {
                HttpEntity r_entity = response.getEntity();
                json = EntityUtils.toString(r_entity);
              Log.i("ja", json);
            } 

        } catch (Exception e) {
            throw new RuntimeException(e.getLocalizedMessage());
        } finally {
            httpclient = null;
            response = null;
            httpclient = null;
        }
    } else {
        throw new RuntimeException("No internet connection");
    }
    return json;

}

我的Grails:

  def image = request.getFile('image')
   image.transferTo(new File('c:/p.png') )

错误:

groovy.lang.MissingMethodException: No signature of method: org.apache.catalina.core.ApplicationHttpRequest.getFile() is applicable for argument types: (java.lang.String) values: [image]
Possible solutions: getXML(), getAt(java.lang.String), getAt(java.lang.String), getLocale(), getInfo(), recycle()
    at mclient.TestController$_closure1.doCall(TestController.groovy:10)
    at mclient.TestController$_closure1.doCall(TestController.groovy)
    at java.lang.Thread.run(Thread.java:662)

0 个答案:

没有答案