|
|
|
Android สอบถามเรื่อง capture photo แล้วจะอัพขึ้น server ใช้ code ตัวไหนครับ |
|
|
|
|
|
|
|
ผมได้แล้วครับ จาก Code นี้
Code (Android-Java)
class ImageUploadTask extends AsyncTask <Void, Void, String>{
String err=null;
@Override
protected String doInBackground(Void... unsued) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(PHP_URL);
ByteArrayBody bab = new ByteArrayBody(data,file_name);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("uploadedfile", bab);
reqEntity.addPart("nameTravel", new StringBody(NameTravel.getText().toString().trim()));
reqEntity.addPart("travelType", new StringBody(spin_type_travel.getSelectedItem().toString().trim()));
reqEntity.addPart("descriptionTravel", new StringBody(Description.getText().toString().trim()));
reqEntity.addPart("moneyTravel", new StringBody(Money.getText().toString().trim()));
reqEntity.addPart("province", new StringBody(spin_province.getSelectedItem().toString().trim()));
reqEntity.addPart("vote1", new StringBody(Integer.toString(vote1.getProgress()).toString().trim()));
reqEntity.addPart("vote2", new StringBody(Integer.toString(vote2.getProgress()).toString().trim()));
reqEntity.addPart("vote3", new StringBody(Integer.toString(vote3.getProgress()).toString().trim()));
reqEntity.addPart("vote4", new StringBody(Integer.toString(vote4.getProgress()).toString().trim()));
reqEntity.addPart("vote5", new StringBody(Integer.toString(vote5.getProgress()).toString().trim()));
reqEntity.addPart("latitude", new StringBody(getLatitude.getText().toString().trim()));
reqEntity.addPart("longitude", new StringBody(getLongitude.getText().toString().trim()));
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(),"UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
return s.toString().trim();
} catch (Exception e) {
err="error"+e.getMessage();
Log.e(e.getClass().getName(), e.getMessage());
return e.getMessage();
}
}
|
|
|
|
|
Date :
2013-03-20 14:28:54 |
By :
nutsai4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จัดไป
|
|
|
|
|
Date :
2013-03-20 17:13:00 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|