我如何在远程位置上传图像

时间:2014-06-09 07:57:03

标签: gwt

我有一个java代码可以在本地驱动器上传图像。现在我想当用户上传图片时我们应该在远程位置上传它我怎样才能实现...

 try {

        String UPLOAD_DIRECTORY = "E:\\uploaded";  

       File uploadsFolder = new File(UPLOAD_DIRECTORY);

       String fileName = item.getName();

       if (fileName != null) {
        fileName = FilenameUtils. getName(fileName); // uploaded file filename
       }

       File uploadedFile = new File(uploadsFolder, fileName);
       item.write(uploadedFile);

       /// Save a list with the received files
       receivedFiles.put(item.getFieldName(), uploadedFile);
       receivedContentTypes.put(item.getFieldName(), item.getContentType());

       /// Send a customized message to the client.
       response += uploadedFile;

      } catch (Exception e) {
       throw new UploadActionException(e);
      }

1 个答案:

答案 0 :(得分:1)

这是服务器端,它与GWT无关。您必须通过http客户端进行多形式发布。

这是一个简短的例子 Java Http Client to upload file over POST

这里是官方的 https://hc.apache.org/httpcomponents-client-ga/httpmime/examples/org/apache/http/examples/entity/mime/ClientMultipartFormPost.java