Я хочу захватить пять изображений в своем приложении и отправил их строку base64 на сервер без сжатия. Я искал в google и читал много статей после этого, я нашел решение для отправки строки base64 без сжатия. Теперь, что я хочу, когда я отправляю только одно изображение, то его сохранение успешно на моем сервере, но когда я отправляю два или более двух изображений, то я получил ошибку ниже. Я не понимаю, в чем проблема. Я думаю, что я делаю неправильно.Несколько изображений base64 Строка не отправляется на сервер без компрессии
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == getActivity().RESULT_OK) {
//user is returning from capturing an image using the camera
if (requestCode == CAMERA_CAPTURE) {
byte[] inputData=null;
//Uri uri = data.getData();
//get the Uri for the captured image
Uri uri = picUri;
Log.d("picUri", uri.toString());
InputStream iStream = null;
try {
iStream = getActivity().getContentResolver().openInputStream(uri);
inputData = getBytes(iStream);
encodedString = Base64.encodeToString(inputData, Base64.DEFAULT);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//carry out the crop operation
performCrop();
} else if (requestCode == PIC_CROP) {
//get the returned data
Bundle extras = data.getExtras();
//get the cropped bitmap
thePic = (Bitmap) extras.get("data");
if (setInImageView.equals("1")) {
imageView1.setImageBitmap(thePic);
image1 =encodedString;
} else if (setInImageView.equals("2")) {
imageView2.setImageBitmap(thePic);
image2 = encodedString;
} else if (setInImageView.equals("3")) {
imageView3.setImageBitmap(thePic);
image3 = encodedString;
} else if (setInImageView.equals("4")) {
imageView4.setImageBitmap(thePic);
image4 = encodedString;
} else if (setInImageView.equals("5")) {
imageView5.setImageBitmap(thePic);
image5 = encodedString;
String str;
str = "1";
}
}
}
}
public void selectImage1() {
try {
//use standard intent to capture an image
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/picture.jpg";
File imageFile = new File(imageFilePath);
picUri = Uri.fromFile(imageFile); // convert path to Uri
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, picUri);
startActivityForResult(takePictureIntent, CAMERA_CAPTURE);
} catch (ActivityNotFoundException anfe) {
//display an error message
String errorMessage = "oops! your device doesn't support capturing images!";
Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show();
}
}
//OnClick for set Image in Image View
public void onClick(View v) {
switch (v.getId()) {
case R.id.camera1:
// code
setInImageView="1";
selectImage1();
break;
case R.id.camera2:
// code
setInImageView="2";
selectImage1();
break;
case R.id.camera3:
// code
setInImageView="3";
selectImage1();
break;
case R.id.camera4:
// code
setInImageView="4";
selectImage1();
break;
case R.id.camera5:
// code
setInImageView="5";
selectImage1();
break;
default:
break;
}
}
public static byte[] getBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int bufferSize = 10240;
byte[] buffer = new byte[bufferSize];
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
return byteBuffer.toByteArray();
}
}
Ниже моя ошибка -
SoapFault - faultcode: 'soap:Server' faultstring: 'There was an exception running the extensions specified in the config file. ---> Maximum request length exceeded.' faultactor: 'null' detail: [email protected]
'отправил свою строку base64 на сервер без сжатия'. Какое сжатие? Я не понимаю. Сначала вы расширили количество байтов на 30% путем кодирования до base64. А теперь ... Почему вы говорите об компрессии? – greenapps
Спасибо greenapps Я получил вашу мысль. Я говорю о том, потому что я видел много примеров, но у меня получается только 40 КБ размер изображения, который мне не подходит, но из этого кода я получил размер изображения 1,4 МБ. Почему он не сохраняет все пять изображений на сервер? Делаю что-то не так? –
Моя проблема заключается в том, что я хочу сохранить все пять изображений, но это дает ошибку, о которой я упоминаю в вышеупомянутом вопросе. Но если я отправлю только одно изображение, то его сохранение на сервере. –