Я знаю, что этот вопрос был задан и получен ответ, но у меня другая проблема. У меня сейчас есть приложение, которое не загружает изображения размером более 5 мегапикселей, но загружает меньшие. Я не уверен, что его 5mp или более 1 МБ, я уверен, что его MP, хотя, я проверял. Как я могу загрузить фотографии всех размеров? Мой код приведен ниже. Пожалуйста, помогите, пожалуйста, оставьте код, а не ссылки, ссылки на ссылки, затем ссылки на код, который может помочь. Спасибо!
Загрузка изображения
@Override
защищенное растровое изображение doInBackground (Object ... objects) {
InputStream is = null;
BufferedInputStream bis = null;
Bitmap bmp = null;
try {
URL url = new URL(Pictureurl);
URLConnection conn = url.openConnection();
conn.connect();
is = conn.getInputStream();
bis = new BufferedInputStream(is);
bmp = BitmapFactory.decodeStream(bis);
return bmp;
} catch (MalformedURLException e) {
return null;
} catch (IOException e) {
return null;
}
}
@Override
protected void onPostExecute(Object resizedBitmap) {
MainPicture.setImageBitmap((Bitmap) resizedBitmap);
connectionProgressDialog.dismiss();
}
Загрузка изображения
public boolean SaveNewPicture (String SelectedFile, String updatedPhotoPath) {
HttpURLConnection conn = null;
DataOutputStream dos = null;
DataInputStream inStream = null;
@SuppressWarnings("unused")
String Message = null;
// Полный путь к имени файла, который должен быть загружен на сервер
Строка exsistingFileName = SelectedFile;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;
@SuppressWarnings("unused")
String responseFromServer = "";
//Server path to the upload.php
String urlString = "http://www.thelinkhookup.com/upload.php";
try
{
//------------------ CLIENT REQUEST
FileInputStream fileInputStream = new FileInputStream(new File(exsistingFileName) );
// open a URL connection to the Servlet
URL url = new URL(urlString);
// Open a HTTP connection to the URL
conn = (HttpURLConnection) url.openConnection();
// Allow Inputs
conn.setDoInput(true);
// Allow Outputs
conn.setDoOutput(true);
// Don't use a cached copy.
conn.setUseCaches(false);
// Use a post method.
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
dos = new DataOutputStream( conn.getOutputStream() );
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + exsistingFileName +"\"" + lineEnd);
dos.writeBytes(lineEnd);
System.out.println("Headers are written");
// create a buffer of maximum size
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// read file and write it into form...
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0)
{
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
// send multipart form data necesssary after file data...
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
// close streams
System.out.println("File is written");
fileInputStream.close();
dos.flush();
dos.close();
}
catch (MalformedURLException ex)
{
return false;
}
catch (IOException ioe)
{
Message = ioe.toString();
return false;
}
//------------------ read the SERVER RESPONSE
try {
inStream = new DataInputStream ( conn.getInputStream() );
String str;
while (( str = inStream.readLine()) != null)
{
//the str contains the server response
System.out.println("Server Response"+str);
}
inStream.close();
//Message = "Should Have Worked";
}
catch (IOException ioex){
return false;
}
try{
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost("http://thelinkhookup.com/UpdatePhotoName.php");
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("Username", MyGlobalInfomation.getUsername()));
postParameters.add(new BasicNameValuePair("Photopath", UpdatedPhotoPath));
postParameters.add(new BasicNameValuePair("localphotopath",SelectedFile ));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
request.setEntity(formEntity);
@SuppressWarnings("unused")
HttpResponse response = client.execute (запрос);
if (SelectedFile! = null || SelectedFile! = "") {
MyGlobalInfomation.setLocalPhotoPath (SelectedFile);
}
}
поймать (исключение е) {
вернуть ложь;
}
вернуть истину;
} * * Тысяча двадцать-один