Android的 - 我想显示文件上传进度用户 [英] Android - I want to show file upload progress to the user

查看:86
本文介绍了Android的 - 我想显示文件上传进度用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上传照片通过在Android SDK中的默认HttpClient的服务器。我想显示进度的用户界面,是有办法找出多少已上载?是否有可能与HttpURLConnection类?

I upload photo to the server via the default HttpClient in Android SDK. I want to show progress in the user interface, is there a way to find out how much has been uploaded? Is it possible with HttpUrlConnection?

推荐答案

有关我了HTTPClient没有工作。其中,在缓冲部件和冲洗调用后发送的总的字节数。什么工作是送了它在套接字级别。

For me HTTPClient didn't work. The bytes where buffered in parts and sent as total after the flush call. What worked was to sent it on socket level.

您可以使用HttpMultipartClient这个(在30-10-2011更新的链接): <一href="http://$c$c.google.com/p/rainbowlibs/source/browse/android/trunk/rainbowlibs/src/it/rainbowbreeze/libs/data/HttpMultipartClient.java?spec=svn94&r=94">http://$c$c.google.com/p/rainbowlibs/source/browse/android/trunk/rainbowlibs/src/it/rainbowbreeze/libs/data/HttpMultipartClient.java?spec=svn94&r=94

You can use the HttpMultipartClient for this (updated link on 30-10-2011): http://code.google.com/p/rainbowlibs/source/browse/android/trunk/rainbowlibs/src/it/rainbowbreeze/libs/data/HttpMultipartClient.java?spec=svn94&r=94

指定每个部分的字节数,并更新while循环的进度:

Specify the amount of bytes for each part and update the progressbar in the while loop:

而((行= reader.readLine())= NULL和放大器;!&安培;!headersEnd)

while (( line = reader.readLine()) != null && !headersEnd)

调用HttpMultipartClient为便接踵而来:

Call the HttpMultipartClient as folow:

HttpMultipartClient httpMultipartClient = new HttpMultipartClient("bluppr.com", "/api/order/create", 80);

FileInputStream fis = new FileInputStream(path + fileName);
httpMultipartClient.addFile(fileName, fis, fis.available());
httpMultipartClient.setRequestMethod("POST");
httpMultipartClient.send();

在服务器端使用:

At the server side use:

<?php

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name'])." has been uploaded " .$_POST["order"]. " post";
} else{
    echo "There was an error uploading the file, please try again!";
}

?>

我用这对Bluppr明信片,工作就像一个魅力。如果您需要更多的信息让我知道。

I used this for Bluppr Postcards, worked like a charm. If you need more info let me know.

这篇关于Android的 - 我想显示文件上传进度用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆