从Android崩溃应用程序上传大视频到PHP服务器

从Android崩溃应用程序上传大视频到PHP服务器,第1张

概述我正在将大型视频上传到php服务器,这会导致应用程序崩溃. 所以,我使用了conn.setChunkedStreamingMode(maxBufferSize); 但它给出了RESPONCE:请求实体太大 服务器端视频以编码形式被接受,因此我使用Base64进行编码. 我正在使用JSON网络服务来上传视频 uploadvideo(&userid,&video,&title,&description 我正在将大型视频上传到PHP服务器,这会导致应用程序崩溃.

所以,我使用了conn.setChunkedStreamingMode(maxBufferSize);
但它给出了RESPONCE:请求实体太大

服务器端视频以编码形式被接受,因此我使用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/android-developers@googlegroups.com/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,bufferSize);    while (bytesRead > 0)    {        dos.write(buffer,bufferSize);        bytesAvailable = fileinputStream.available();        bufferSize = Math.min(bytesAvailable,maxBufferSize);        bytesRead = fileinputStream.read(buffer,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());    }
解决方法 你应该将大文件分成小部分然后尝试发送.并在服务器上加入这个小部分 总结

以上是内存溢出为你收集整理的从Android崩溃应用程序上传大视频到PHP服务器全部内容,希望文章能够帮你解决从Android崩溃应用程序上传大视频到PHP服务器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1124533.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存