开发者

How to upload video to PHP SERver from Android

Hi Guys i m 开发者_如何学编程using following code but getting error0 as response . Please help in following code as i m near to success.

 public void video()
 {
    File file = new File(exsistingFileName);
    try {
        HttpClient client = new DefaultHttpClient();  
        String postURL = "http://10.0.0.27/sportscloud/devices/uploadBlogData.php";
        HttpPost post = new HttpPost(postURL); 
        FileBody bin = new FileBody(file);
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);  

        reqEntity.addPart("email", new StringBody("test1@nga.com", "text/plain", Charset.forName( "UTF-8")));
        reqEntity.addPart("gameId", new StringBody("1024", "text/plain", Charset.forName( "UTF-8")));
        reqEntity.addPart("source", new StringBody("phone", "text/plain", Charset.forName("UTF-8"))); 
        reqEntity.addPart("uploadfile",bin );
        post.setEntity(reqEntity);  
        HttpResponse response = client.execute(post);     

        HttpEntity resEntity = response.getEntity();  
        if (resEntity != null) {    
                   Log.i("RESPONSE",EntityUtils.toString(resEntity));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}


what kind of error do you get? more info will be helpfull :)
try this

InputStream is = this.getAssets().open(exsistingFileName);
byte[] data = IOUtils.toByteArray(is);
InputStreamBody isb = new InputStreamBody(new ByteArrayInputStream(data),"uploadedFile");
reqEntity.addPart("uploadfile",isb);


good luck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜