我要送服務器side.Right三種不同的圖像,現在一個 圖像上傳thrice.But我選擇了三個不同的形象。發送多個圖片服務器:一個形象三次發送到服務器問題
因爲我給了count = 0,那麼它需要第一張圖像併發送第一張圖像三次到服務器。
如果我給count = 1,那麼第二張圖像會一次向服務器發送 三次。
我不知道如何給0,1和2一次發送三張圖像。因此,我可以一次發送三張圖像發送給服務器。
logcat的:
02-11 04:32:20.565: E/params[0](16395): 0
02-11 04:32:20.582: E/ParamsArray(16395): [0, pk0.jpg]
MainActivity.java:
public class MainActivity extends Activity {
private Button upload, pick;
MultipartEntity entity;
GridView gv;
int count = 0;
public ArrayList<String> map = new ArrayList<String>();
Bundle b;
TextView noImage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
upload.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new ImageUploadTask().execute(count + "", "pk" + count + ".jpg");
/*Log.e("url", url);
new UserProfileUpdateAsynTask().execute(url);*/
}
});
}
class ImageUploadTask extends AsyncTask<String, Void, String> {
ProgressDialog dialog;
String url = "";
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(MainActivity.this);
dialog.setMessage("Loading...");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected String doInBackground(String... params) {
HttpEntity resEntity;
int i = Integer.parseInt(params[0]);
Log.e("params[0]",""+i);
Bitmap bitmap = decodeFile(map.get(i));
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
entity = new MultipartEntity();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
try {
Log.e("ParamsArray",""+Arrays.toString(params));
entity.addPart("filename[0]", new ByteArrayBody(data,"image/jpeg", params[1]));
entity.addPart("filename[1]", new ByteArrayBody(data,"image/jpeg", params[1]));
entity.addPart("filename[2]", new ByteArrayBody(data,"image/jpeg", params[1]));
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
resEntity = response.getEntity();
String entityContentAsString = EntityUtils.toString(resEntity);
return entityContentAsString;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (result != null) {
dialog.dismiss();
Log.e("Update_profile", result);
}
}
}
}
任何人都可以幫我this.Thank你。
現在它沒有發送給服務器的任何圖像.initially int count = 0;這就是爲什麼它不是在for循環中執行,然後我設置我<3在循環中。它三次拍攝三個圖像。 – Steve
請顯示您用於保存目的的服務器代碼。它看起來像服務器正在複製。 –