简单纪要: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();
        }
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM