使用http post request android上传视频

时间:2014-05-26 07:22:12

标签: android androidhttpclient chunks

我需要使用http服务调用将视频上传到服务器。

为此,我有一个如下服务电话。

http://capmem.omsoftware.co/Event/UploadVideo?callback=localJsonpCallback&chunk=&totalSize=&Filename=&UserID=&EventID=&comment=&VideoLength=

我如何获得大量字节传入" chunk"服务电话中的参数。?

这是我的代码

int mychunkSize = 100 * 1024;


            realPath = getRealPathFromURI(videoFileUri);
            System.out.println("file name" + realPath);

            long size1 = realPath.length();
            size = Long.toString(size1);

            System.out.println("total size" + size);
            long chunks1 = size1 < mychunkSize ? 1
                    : (realPath.length() / mychunkSize);
            chunks = Long.toString(chunks1);

这是获取大块字节(块)的正确方法吗?

请帮助..

1 个答案:

答案 0 :(得分:2)

使用multipart上传

Uploading large files from android to c# WCF Rest Service

HttpClient httpclient = new DefaultHttpClient();

            HttpPost httppost = new HttpPost(url);


            MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            entity.addPart("FileData", new FileBody(file));


            httppost.setEntity(entity);
            HttpResponse response = httpclient.execute(httppost);

            String responseData = EntityUtils.toString(response.getEntity());