简单纪要:java后台实现 往url上传文件

将文件 post 到一个上传地址上存储:

  public static void main(String[] args) {
        HttpClient client = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://uploadurl");// 上传地址
        FileBody fileBody = new FileBody(new File("d:\test.mp4"));// 文件位置
        StringBody stringBody;
        try {
            MultipartEntity entity = new MultipartEntity();
            entity.addPart("file", fileBody);
            httpPost.setEntity(entity);
            HttpResponse response = client.execute(httpPost);
            if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
                // 上传成功
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
原文地址:https://www.cnblogs.com/Rnan/p/10710682.html