我上傳大型視頻到PHP服務器,該服務器崩潰的應用程序。上傳大視頻從Android PHP服務器崩潰應用
所以,我已經使用conn.setChunkedStreamingMode(MAXBUFFERSIZE);
但它給性反應:請求實體太大
服務器端視頻的編碼形式接受的,所以我用的Base64編碼。
我使用JSON網絡服務上傳視頻
uploadvideo(&userid,&video,&title,&description,&type)
我已經搜索很多,但不能得到解決。 任何人能告訴我
http://www.coderzheaven.com/2012/03/29/uploading-audio-video-or-image-files-from-android-to-server/
http://www.mail-archive.com/[email protected]/msg92856.html
哪一個更好,以及如何添加參數?像DIS
try {
FileInputStream fileInputStream = new FileInputStream(myFile.getAbsolutePath()); //(new File(selectedPath));
// 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.setChunkedStreamingMode(maxBufferSize);
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=\"userid\""+ lineEnd + lineEnd);
dos.writeBytes(strUserid+lineEnd);
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);
}
String encodeurl = Base64.encodeBytes(buffer);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"video\""+ lineEnd + lineEnd);
dos.writeBytes(encodeurl+lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"title\""+ lineEnd + lineEnd);
dos.writeBytes(strVideoName+lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"description\""+ lineEnd + lineEnd);
dos.writeBytes(strVideoComments+lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"type\""+ lineEnd + lineEnd);
dos.writeBytes(type+lineEnd);
responseMsg = conn.getResponseMessage();
// close streams
System.out.println("Debug File is written");
fileInputStream.close();
dos.flush();
dos.close();
}
catch (MalformedURLException ex)
{
System.out.println(("Debug Error: " + ex.getMessage()));
}
catch (IOException ioe)
{
System.out.println("Debug Error: " + ioe.getMessage());
}
//------------------ read the SERVER RESPONSE
try {
inStream = new DataInputStream (conn.getInputStream());
System.out.println("Input Stream :: "+inStream.toString());
String str;
while ((str = inStream.readLine()) != null)
{
System.out.println("Debug Server Response "+str);
}
inStream.close();
}
catch (IOException ioex){
System.out.println("Debug Error: " + ioex.getMessage());
}
嗨chintan我面臨同樣的問題,我的代碼可以幫助你如何實現,如果它被解決。我使用相同的源只上傳<12 MB的視頻,如果超過這個尺寸的話。該怎麼辦? –