내 안드로이드 앱의 동영상을 서버에 업로드하려고합니다. 내 앱이 내 앱을 표시하려고 시도 할 때 04-23 13:07:41.602: ERROR/dalvikvm-heap(519): Out of memory on a 15607356-byte allocation.
왜 오류가 발생하는지 알지 못합니다. 내 질문은 비디오를 업로드 할 수 있습니까? 아래의 코드를 사용하여 50메가바이트 개까지 크기? 누군가가 알고 있다면
의미서버에 최대 50MB까지 동영상 업로드
private void doFileUpload(){
HttpURLConnection conn = null;
DataOutputStream dos = null;
DataInputStream inStream = null;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 8*1024*1024;
Cursor c = (MainscreenActivity.JEEMAHWDroidDB).query((MainscreenActivity.TABLE_Name), new String[] {
(MainscreenActivity.COL_HwdXml)}, null, null, null, null,
null);
if(c.getCount()!=0){
c.moveToLast();
for(int i=c.getCount()-1; i>=0; i--) {
value=c.getString(0);
}
}
String urlString = value+"/upload_file.php";
try
{
//------------------ CLIENT REQUEST
UUID uniqueKey = UUID.randomUUID();
fname = uniqueKey.toString();
Log.e("UNIQUE NAME",fname);
FileInputStream fileInputStream = new FileInputStream(new File(selectedPath));
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
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=\"" + fname + "."+extension+"" + lineEnd);
dos.writeBytes(lineEnd);
bytesAvailable = fileInputStream.available();
System.out.println("BYTES:--------->"+bytesAvailable);
bufferSize = Math.min(bytesAvailable, maxBufferSize);
System.out.println("BUFFER SIZE:--------->"+bufferSize);
buffer = new byte[bufferSize];
System.out.println("BUFFER:--------->"+buffer);
bytesRead = fileInputStream.read(buffer,0,bufferSize);
System.out.println("BYTES READ:--------->"+bytesRead);
while (bytesRead > 0)
{
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
System.out.println("RETURNED");
}
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
Log.e("Debug","File is written");
fileInputStream.close();
dos.flush();
dos.close();
}
catch (MalformedURLException ex)
{
Log.e("Debug", "error: " + ex.getMessage(), ex);
}
catch (IOException ioe)
{
Log.e("Debug", "error: " + ioe.getMessage(), ioe);
}
//------------------ read the SERVER RESPONSE
try {
inStream = new DataInputStream (conn.getInputStream());
String str;
while ((str = inStream.readLine()) != null)
{
Log.e("Debug","Server Response "+str);
}
inStream.close();
}
catch (IOException ioex){
Log.e("Debug", "error: " + ioex.getMessage(), ioex);
}
을 데이터를 게시하려면이 사용해야하는 경우 httppost 및 다중 엔티티이 코드는 "메모리 부족"같은 오류가 발생해야합니다 사용 후 uploading.its 강제로 내 활동을 마감했습니다 –
내 앱이 최대 4.1MB까지 업로드됩니다. 그 이상으로 업로드하려고 시도하면 앱이 강제 종료됩니다. 여기에서 pblm이 발생합니까? 아무도 모른다면 this.Please 나를 조금 도와 줄래 –