我想使用名称、块、文件数据的参数将我的文件从 android 设备发送到 web api。我有这个代码:它不会对我返回任何错误我不知道我做错了什么。请帮助我花了很多时间在这上面,但它仍然不起作用。
FileBody localFileBody = new FileBody(new File("/storage/sdcard0/Pictures/Images/angel_productshot.jpg"),
"image/jpg");
MultipartEntity localMultipartEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 15000);
HttpConnectionParams.setSoTimeout(httpParameters, 15000);
HttpPost httpPost = new HttpPost(
"http://phdsafar4.myserver.com.ph:1217/api/fileupload");
HttpClient httpclient = new DefaultHttpClient(httpParameters);
httpPost.addHeader("Authorization","Basic " + Base64.encodeToString(
(username + ":" + password).getBytes(), Base64.NO_WRAP));
httpPost.setHeader("Content-Type", "multipart/form-data");
httpPost.setHeader("Accept", "application/image");
localMultipartEntity.addPart("name", new StringBody(filename));
localMultipartEntity.addPart("chunk", new StringBody("1"));
localMultipartEntity.addPart("file data", localFileBody);
httpPost.setEntity(localMultipartEntity);
HttpResponse localHttpResponse = httpclient.execute(httpPost);
Log.i("response upload", localHttpResponse.toString());
Log.i("Multipart Entity", localMultipartEntity.toString());