尝试将文件上载到Apache服务器时出现Android问题
我在尝试将文件上载到Web服务器时遇到问题 这是我正在使用的代码:尝试将文件上载到Apache服务器时出现Android问题,android,file,upload,http-post,Android,File,Upload,Http Post,我在尝试将文件上载到Web服务器时遇到问题 这是我正在使用的代码: File file = new File(fileUri.getPath()); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(URL_connect); Log.e("subiendo archivo",fileUri.getPath()); InputStream
File file = new File(fileUri.getPath());
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL_connect);
Log.e("subiendo archivo",fileUri.getPath());
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
//Do something with response...
} catch (Exception e) {
e.printStackTrace();
Toast toast1 = Toast.makeText(getApplicationContext(),"Error "+e, Toast.LENGTH_SHORT);
toast1.show();
Vibrator vibrator =(Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(200);
}
但是没有办法,文件没有上传到服务器,我正在服务器端尝试:
$file = $_FILES["file"];
$nombre_archivo = $_FILES['file']['name'];
$tipo_archivo = $_FILES['file']['type'];
$tamano_archivo = $_FILES['file']['size'];
$temporal = $_FILES['file']['tmp_name'];
move_uploaded_file($temporal, "../img/media/".$nombre_archivo);
在LogCat中,与上传无关,它只打印Log.e(“上传文件”,“文件名和路径”)
问题出在哪里?解决了,而是使用了我之前发布的代码: 以下信息:
已解决,而不是使用我之前发布的代码: 以下信息:
上传2mb文件时,您是否注意到任何问题?上传2mb文件时,您是否注意到任何问题?此代码有145个http错误是的,我在几个月前添加了答案和正确的代码,您可以在下面看到。此代码有145个http错误是的,我在几个月前添加了答案和正确的代码,您可以在下面看到。
try {
MultipartEntity entity = new MultipartEntity();
Log.e("enviando", fileUri.getPath());
entity.addPart("reporte", new StringBody(reporte));
entity.addPart("usuarioID", new StringBody(user));
entity.addPart("archivo", new FileBody(file));
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}