2014-11-20 27 views

Trả lời

4

Để tải lên một tập tin một cách hiệu quả là sử dụng HttpPost với multipart/form

multipart/form Các tập tin nội dung hoặc là lưu trữ trong bộ nhớ hoặc tạm thời trên đĩa. Trong cả hai trường hợp, người dùng có trách nhiệm sao chép nội dung tệp sang cấp phiên hoặc lưu trữ liên tục và nếu muốn. Các kho tạm thời sẽ bị xóa vào cuối xử lý yêu cầu

Tham khảo này Upload Files from Android to a Website/Http Server using Post

1

thử mã này

HttpClient client = new DefaultHttpClient(); 
    HttpPost post = new HttpPost(URL); 

    MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 

    //Path of the file to be uploaded 
    String filepath = params[0]; 
    File file = new File(filepath); 
    ContentBody cbFile = new FileBody(file, SET_MIMETYPE);//"audio/basic" 
    try { 

     mpEntity.addPart(FILE_NAME, cbFile); 
     post.setEntity(mpEntity); 
     HttpResponse response1 = client.execute(post); 
     HttpEntity resEntity = response1.getEntity(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

hoặc cũng tham khảo liên kết này "http://www.androidhive.info/2014/12/android-uploading-camera-image-video-to-server-with-progress-bar/" Cảm ơn

Các vấn đề liên quan