왜 비트 맵을 바이트 배열로 변환하여 서버로 전달할 수 없습니까? 다음은 서버에 비트 맵을 보내는 코드입니다.
AsyncTask에서 이러한 작업을 수행하십시오.
public class UploadPicture extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
// show your progress bar
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
// wrap up all your upload code here..
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
// stop your progress bar
}
}
전화하여 부울을 확인한 후이 클래스 :
if(AutoUploadPic)
{
new UploadPicture().execute();
}
else
{
// Your code here..
}
//하여 doInBackground 클래스에서 다음을 수행하십시오
이
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
// Preview_bitmap은 당신이 보낼 필요 하나입니다 서버. 나는 여기에 압축 및 서버에이를 보내고있다 :
HttpPost postRequest = new HttpPost(Constant.uploadImagesAPI
+ Constant.mDeviceID);
ByteArrayBody bab = new ByteArrayBody(data, ".jpg");
MultipartEntity reqEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("image", bab);
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder mUploadResponse = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
mUploadResponse = mUploadResponse.append(sResponse);
}
JSONObject mUploadResponseObject = new JSONObject(
mUploadResponse.toString());
mUploadResponseObject.getJSONArray("response");
try {
JSONArray jsonArray = mUploadResponseObject
.getJSONArray("response");
for (int i = 0; i < jsonArray.length(); i++) {
uploadStatus = jsonArray.getJSONObject(i)
.getJSONObject("send").getString("message");
uploadPhotoID = jsonArray.getJSONObject(i)
.getJSONObject("send").getString("id");
Constant.imageUploadedFlag = true;
}
} catch (Exception e) {
serverUploadException = true;
}
} catch (Exception e) {
}
// PHP 코드 :
$to = $_REQUEST['deviceid'];
//$timestamp = $_REQUEST['timestamp'];
$path=PATH.'upload/';
//$path1=PATH.'newupload/';
//$name = $_FILES['image']['name'];
//$str=explode(".",$name);
//$imname=$str[0];
$filename=upload::save($_FILES['image']);
$file_name1= basename($filename);
$docroot= $_SERVER['DOCUMENT_ROOT'];
//$root=$docroot.'/newupload/';
$roots=$docroot.'/upload/';
$url = $path.$file_name1;
$send = $this->api->upload_images($to,$url);
if($send)
{
$json_response[] = array("send" =>
array("id"=> $send,
"message"=>"Message Sent Successfully",
"status"=>1));
}
echo json_encode(array ('response' =>$json_response));
break;
지금까지 사용해 본 Raghu는 무엇입니까? –
글쎄, PHP와 아마도 웹 서버를 사용하기 때문에 http 업로드를 구현해야한다. 여기에 어떤 질문이 있습니까? – arkascha