Android Spring File Upload OutofMemory

后端 未结 1 1457
谎友^
谎友^ 2021-01-03 08:49

I am trying to use the following code to upload a file to a rest api. This code works fine for files up to around 20MB, but bigger files will give an OutOfMemoryError<

相关标签:
1条回答
  • 2021-01-03 09:34

    Analyzing the code, it seems Spring for Android buffers its data before sending it - that's why your OOE. There is a trick however (but so far I've made it possible to work only for API level 9 above): you can disable the buffering for its connection factory but ONLY if the RestTemplate has no ClientHttpRequestInterceptor list set (now how stupid is that ?) - lucky you as you didn't set one. So in your case the situation is very simple, just call factory.setBufferRequestBody(false); after you've instantiated it.

    0 讨论(0)
提交回复
热议问题