0

i have found this code HttpURLConnection to Send image , audio and video files with parameter may (String or Json String) Android and it works perfectly with video, images and audio. But when i send a large video i get this error :

Throwing OutOfMemoryError "Failed to allocate a 28 byte allocation with 0 free bytes and -1856B until OOM" (recursive case)
computingfreak
  • 4,939
  • 1
  • 34
  • 51

1 Answers1

0

The video is simply too large to work with in RAM all at once, so you'll either need to make the file smaller, or work with it in pieces, in which case your server will need to be configured to accept chunks of streamed data as well. From the HttpURLConnection docs:

To upload data to a web server, configure the connection for output using setDoOutput(true). For best performance, you should call either setFixedLengthStreamingMode(int) when the body length is known in advance, or setChunkedStreamingMode(int) when it is not. Otherwise HttpURLConnection will be forced to buffer the complete request body in memory before it is transmitted, wasting (and possibly exhausting) heap and increasing latency.

So setting setChunkedStreamingMode() might solve your issue.

Also you might take a look at this question: Upload large file in Android without outofmemory error

Community
  • 1
  • 1
NoChinDeluxe
  • 3,446
  • 1
  • 16
  • 29
  • i have set conn.setChunkedStreamingMode(1024); and work exellent now so you think need to add more because im new in developer so i dont know much thinks if you can write an example anyways i will accept this answer because is right – Fation Jesmina Mashi Dec 21 '15 at 18:37
  • I'm not sure what you're asking. – NoChinDeluxe Dec 21 '15 at 18:40
  • I have create a app record video the video save in sdcard after when i click stop the video save and sent to server after it send to server i want to delete the video from sdcard – Fation Jesmina Mashi Dec 21 '15 at 18:42
  • You just create a File from the path of the video, then call `delete()` on the File. See the docs for more info: http://developer.android.com/reference/java/io/File.html#delete() – NoChinDeluxe Dec 21 '15 at 18:46
  • yes thank you i know that i just tell you what i want to do and for sent large video i use that link that you have tell me , is the same of the link i have post and know works 100% thank you so much Respect From Albania !!! – Fation Jesmina Mashi Dec 21 '15 at 18:50