1
내 앱에서 이미지를 캡처하여 서버에 업로드하고 있습니다. 캡처 및 업로드 부분은 5 메가 픽셀 인 안드로이드 장치에서 잘 작동합니다.Android 앱의 서버에 이미지 업로드
사진을 찍을 때 앱이 가끔 충돌합니다. 사람들이 메가 픽셀 설정이 높은 사진을 찍으면 사진이 업로드되지 않고 앱이 다운되는 것을 발견했습니다.
충돌없이 업로드 할 수있는 8 메가 픽셀 사진의 크기를 줄이는 방법은 무엇입니까? 캡처 한 이미지를 압축해야합니까? 다음은 이미지
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE,fileName);
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.ACTION_IMAGE_CAPTURE, capturedImage);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(intent, 3);
public void onActivityResult(int requestCode, int resultCode, final Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 3)
{
String[] projection = { MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(mCapturedImageURI, projection, null, null, null);
int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
capturedImage = cursor.getString(column_index_data);
String url = "http://xxxxxxxxxxxxxx.com/device_upload.php";
new ProfileAddImageFileAsync().execute(url);
}
}
을 다음과 업로드가 완료 될 때까지
다음과 같이 내가 진행 대화 상자를 실행하고 나는이으로 onActivity 결과에 이미지를 업로드하고를 캡처하는 내 코드입니다 class ProfileAddImageFileAsync extends AsyncTask<String, String, String>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
showDialog(DIALOG_DOWNLOAD_PROGRESS);
}
protected String doInBackground(String... Aurl)
{
HttpURLConnection connection = null;
DataOutputStream outputStream = null;
DataInputStream inStream = null;
try
{
URL urlServer = new URL(aurl[0]);
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
int maxBufferSize = 1*1024*1024;
FileInputStream fileInputStream = new FileInputStream(new File(capturedImage));
connection = (HttpURLConnection) urlServer.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
outputStream = new
DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"userfile\";filename=\"" + capturedImage +"\"" + lineEnd);
outputStream.writeBytes(lineEnd);
bytesAvailable = fileInputStream.available();
Log.e("bytesAvailable ",""+bytesAvailable);
bufferSize = Math.min(bytesAvailable, maxBufferSize);
Log.e("bufferSize ",""+bufferSize);
byte[] buffer = new byte[bufferSize];
Log.e("bufer ",""+buffer);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0)
{
outputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + twoHyphens +lineEnd);
@SuppressWarnings("unused")
int serverResponseCode = connection.getResponseCode();
@SuppressWarnings("unused")
String serverResponseMessage = connection.getResponseMessage();
fileInputStream.close();
outputStream.flush();
outputStream.close();
}
catch (Exception ex)
{
Log.e("SD Card image upload error: ","" + ex.getMessage());
}
try
{
inStream = new DataInputStream (connection.getInputStream());
String str;
while ((str = inStream.readLine()) != null)
{
IMAGE_RESPONSE = str;
ServerPost(str);
}
inStream.close();
}
catch (IOException ioex)
{
Log.e("SD card doFile upload error: ","" + ioex.getMessage());
}
return null;
}
protected void onProgressUpdate(String... Progress)
{
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
}
protected void onPostExecute(String unused)
{
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
}
}
제 친구를 도와주세요, 위의 코드는 제 5MP 카메라의 제 작업 코드입니다.
앱이 충돌 할 때 어떤 오류가 발생합니까? 세부 사항을 알 수 없었습니까? –
죄송합니다. 세부 정보를 얻을 수 없습니다 ... –
ACRA를 살펴볼 수 있습니다. http://code.google.com/p/acra/에서 도움을받을 수 있습니다. –