ContainX/openstack4j

Using byte array to upload a large file to swift cause OOM error

jianhaozh opened this issue · 0 comments

i using openstack4j <v 3.1.0> to upload a file to swift, size about 1.7GB,cause OOM error with okhttp

i view the code found that in org.openstack4j.connector.okhttp.httpCommand.execute(), it load the byte[] from request.entity() to build a RequestBody Instance.
here ,i got my solution:

if(FileInputStream.class.isAssignableFrom(request.getEntity.getClass())){
   FileInputStream is = (FileInputStream)request.getEntity();

   Field pathField = FileInputStream.class.getDeclaredField("path");
   pathField.setAccessible(true);
   File f = new File((String)pathField.get(is));
   body = RequestBody.create(MediaType.parse(request.getContentType()),f);
} else if(.....
...... //origin code

okhttp support upload a File object to do a post request

thankx