I used httpclient but i got 411 error code!

i am desperately looking for any solution to avoid buffering for my
audio streams.

any help would be appreciated


On Apr 29, 12:39 pm, zeeshan <genx...@gmail.com> wrote:
> Hi Mike,
>
> thanks for the reply.
>
> this link is very helpfull but my problem is still there, i need to
> use HttpURLConnection as above and post it without buffering; i dont
> know the length of my stream.
>  i tried conn.setChunkedStreamingMode(1024*4); now it doesn't buffer
> but unable to post.
>
> please advise how can i post without buffering if i dont know my
> stream length. ?
>
> On Apr 28, 4:05 pm, Mike Baroukh <mike.baro...@gmail.com> wrote:
>
> > Maybe you could try using httpclient ?
> > haven't tried myself but using "chunked" request, the output will not be
> > buffered.
> > for exemple, 
> > cfhttp://www.java-tips.org/other-api-tips/httpclient/how-to-use-unbuffe...
>
> > Mike
>
> > zeeshan a écrit :
>
> > > Hi Experts,
>
> > > I need to post some files on my server, it works fine for small files
> > > like 1mb but when i try for more than 4 mb ; it force close because of
> > > memory overload.
>
> > > please have a look on my code below:
>
> > >    URL url = new URL(uri);
> > >    URLConnection conn = url.openConnection();
>
> > >                    String boundary = "myboundary";
> > >                    conn.setDoOutput(true);
>
> > >                    conn.setDoInput(true);
> > >                    conn.setUseCaches(false);
> > >                    conn.setRequestProperty("Connection","Keep-Alive");
> > >                    conn.setRequestProperty("user-
> > > agent",this.user_agent);
> > >                    conn.setRequestProperty("accept-
> > > language",this.accept_language);
> > >                    conn.setRequestProperty("user-agent-
> > > id",this.user_agent_id);
> > >                    conn.setRequestProperty("Content-Type","multipart/
> > > form-data; boundary=" + boundary);
> > >                    DataOutputStream wr = new DataOutputStream
> > > (conn.getOutputStream());
> > >                    // Send the normal form data
>
> > >                    Iterator i = parameters.entrySet().iterator();
> > >                    while (i.hasNext()) {
> > >                        Map.Entry param = (Map.Entry)i.next();
> > >                        wr.write( ("--" + boundary + "\r\n").getBytes
> > > () );
> > >                        wr.write( ("Content-Disposition: form-data; name=
> > > \""+(String)param.getKey()+"\"\r\n\r\n").getBytes());
>
> > >                        wr.write( ((String)param.getValue() +
> > > "\r").getBytes());
>
> > >                        wr.flush();
> > >                    }
> > >                   /* wr.write( ("\r--" + boundary + "--\r\n").getBytes
> > > ());
> > >                    wr.flush();*/
> > >                  if(includeFiles){
> > >                    int bytesRead = 0;
>
> > >                    byte [] buffer = new byte[1024*4];
> > >                    InputStream is;
> > >                    Iterator i2 = fileParameters.entrySet().iterator
> > > ();
> > >                    while (i2.hasNext()) {
>
> > >                        Map.Entry param = (Map.Entry)i2.next();
> > >                        String filekey = (String)param.getKey();
> > >                        String fileName = (String)param.getValue();
>
> > >                        wr.write( ("--" + boundary + "\r\n").getBytes
> > > () );
> > >                        wr.write( ("Content-Disposition: form-data; name=
> > > \""+(String)param.getKey()+"\"; ").getBytes());
>
> > >                        if(filekey.endsWith("message[audio]")){
> > >                             if(fileName.contains("/sdcard")){
> > >                                     wr.write( ("filename=\"" + fileName +
> > > "\"\r").getBytes());
> > >                                            File file = new File(fileName);
> > >                                                Uri ab= 
> > > Uri.parse(fileName);
> > >                                                is = new 
> > > FileInputStream(fileName);}
> > >                             else {
> > >                                     wr.write( ("filename=\"" + 
> > > fileName.concat
> > > (".amr") + "\"\r").getBytes());
> > >                                     is = this.cr.openInputStream( 
> > > Uri.parse
> > > (fileName));}
> > >                        wr.write( ("Content-Type: audio \r\n\r
> > > \n").getBytes());
> > >                        wr.flush();
>
> > >                        /*File file = new File(fileName);
> > >                        Uri ab= Uri.parse(fileName);
> > >                        is = new FileInputStream(fileName);*/
> > >                        }
> > >                        else{
> > >                             if(fileName.contains("/sdcard")){
>
> > >                                            File file = new File(fileName);
> > >                                            //long temp=file.length();
> > >                                                Uri ab= 
> > > Uri.parse(fileName);
> > >                                                is = new 
> > > FileInputStream(fileName);}
> > >                             else {
>
> > >                                     is = this.cr.openInputStream( 
> > > Uri.parse
> > > (fileName));}
>
> > >                        wr.write( ("filename=\"" + fileName +
> > > "\"\r").getBytes());
> > >                        wr.write( ("Content-Type: image \r\n\r
> > > \n").getBytes());
> > >                        wr.flush();
>
> > >                        }
>
> > >                        //FileInputStream is = new FileInputStream(new
> > > File(fileName));
>
> > >                        //bytesAvailable = is.available();
>
> > >                        while( (bytesRead = is.read(buffer)) > 0) {
> > >                            wr.write(buffer,0,bytesRead);
> > >                            wr.flush();
> > >                        }
> > >                        if(i2.hasNext()){
> > >                        wr.write( ("\r\n").getBytes());
> > >                        }
> > >                    }
> > >                   }
> > >                    wr.write( ("\r--" + boundary + "--\r\n").getBytes());
> > >                    wr.flush();
>
> > >                wr.close();
> > >              }
> > >                    ///////////////////////////////
>
> > > i believe there is somewhere memory leakage but dont know where, i
> > > have done a lot research but not successfull.
>
> > > please let me know if u figure out any problem in my code
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to