ContainX / openstack4j

A Fluent OpenStack SDK / Client Library for Java
http://openstack4j.com
Other
290 stars 366 forks source link

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

Open jianhaozh opened 5 years ago

jianhaozh commented 5 years ago

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