我想通过将图像发送到 php 脚本来上传图像。如果互联网连接良好,它工作正常。但有时它不起作用。例如,当互联网连接速度很慢时。因此,我正在寻找一种以慢速连接上传图像的方法。我能做些什么?文件大小已经很小了,大约 40kb。代码应尝试上传图像,直到完成。
编辑:上传代码:
public void upload(String uploadImage){
SharedPreferences settings = getSharedPreferences("App", 0);
String emailaddress = settings.getString("mailaddress", null);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",uploadImage));
nameValuePairs.add(new BasicNameValuePair("email", emailaddress));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://domain.de/uploadImage.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
try {
Thread.sleep( 10000 );
}catch (InterruptedException e1) {
e1.printStackTrace();
}
upload(uploadImage);
}
}