I have tried to upload large videos to server using Restful APIs with the help of Retrofit. But each and every time I unable to upload it via this scenario. This works fine for small videos around 100 MBs but its not eligible for larger than 300 MBs.
- What is needs to upload very large files to server? Ans : I am creating Web Series playing application like(Netflix, Amazon Prime, etc) and there is also a Administrator role. Admin can upload web series via mobile and its possibly very large in size around 400 MB to 1 GB.
Process I done : simply I create foreground service and bind notification titled "Video is uploading". Because this task is very long time taken so I need to do that. After that I making API call inside from this service.
Now the actual exception happens while I received video from gallery and uploading to server then exception arise. Exception : java.lang.OutOfMemoryError: Failed to allocate a 392080272 byte allocation with 25165824 free bytes and 318MB until OOM, target footprint 227699960, growth limit 536870912
private var call: Call<ResponseBody?>? = null
private fun callAPI(data: VideoUpload) {
val str = "text/plain"
val videoFile = RequestBody.create("*/*".toMediaTypeOrNull(), data.file)
val videoBody = MultipartBody.Part.createFormData("episode_file", data.file.name, videoFile)
val apiInterface = RetrofitClient.getRetrofitInstance(applicationContext)!!.create(ApiInterface::class.java)
val listener = this
val context = this
try {
System.gc()
ioScope.launch {
call = apiInterface.addEpisode(
videoBody,
RequestBody.create(str.toMediaTypeOrNull(), data.episodeName),
RequestBody.create(str.toMediaTypeOrNull(), data.episodeDuration),
RequestBody.create(str.toMediaTypeOrNull(), data.episodeDesc),
RequestBody.create(str.toMediaTypeOrNull(), data.webSeriesId)
)
APIResponse.callRetrofitCustom<ResponseBody>(call, AppConstants.ADD_EPISODE, context, listener)
}
} catch (e: IOException) {
Log.e(TAG, "callAPI: ${e.localizedMessage}")
}
}
/* Background young concurrent copying GC freed 8(47KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 223MB/223MB, paused 233us total 395.877ms*/
Please provide required solution. Thanks in advance.