Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

499
Views
How is it possible to upload large files with Volley? ( Android )

I would like to upload large files in a POST request using Volley. I tried to use a VolleyMultiPartRequest library, but I get java.lang.OutOfMemoryError:

2020-11-13 19:14:06.636 18802-18802/com.example.myproject E/MainActivity: Tried to start foreground service from background
2020-11-13 19:14:09.730 18802-19082/com.example.myproject E/AndroidRuntime: FATAL EXCEPTION: Thread-15
    Process: com.example.myproject, PID: 18802
    java.lang.OutOfMemoryError: Failed to allocate a 303955984 byte allocation with 8388608 free bytes and 108MB until OOM, max allowed footprint 162626224, growth limit 268435456
        at java.util.Arrays.copyOf(Arrays.java:3164)
        at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)
        at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
        at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
        at com.example.myproject.utils.VolleyMultiPartRequest2.getBody(VolleyMultiPartRequest2.java:109)
        at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:275)
        at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:249)
        at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:94)
        at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:123)
        at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)
        at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
        at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)

All of the libraries like VolleyPlus MultiPartRequest overrides the function public byte[] getBody(). This seems to be the problem, because if a large file is converted into a byte array, then it can not fit into the memory. I need to send the request in chunks. How is that possible?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Volley has some known issues with large file uplaod.

Use multipart file upload for large files, for instance (with retrofit):

public interface FileUploadService {

    @Multipart
    @POST("/upload")
    void upload(@Part("myfile") TypedFile file,
                @Part("description") String description,
                Callback<String> cb);
}

For your reference : https://futurestud.io/blog/retrofit-how-to-upload-files/

over 4 years ago · Santiago Trujillo Report

0

Read this: Volley Issue

From the link: "It[volley] inherently requires that the full request/response be storable in memory, and for video uploads it makes far more sense to stream them incrementally over the network from another source (i.e. disk), to support resume of partial uploads, etc, in a way that Volley's API inherently doesn't support."

over 4 years ago · Santiago Trujillo Report

0

As @CommonsWare mentioned in the comment below the question - you should drop Volley(at least for now). Some time ago they even wanted to deprecate Volley because it depends on Apache HttpClient which is deprecated since API 23, but as far as I know google still supports it and has intentions to make it more modern.

For now stick to the Retrofit and/or underlying OkHttp which leverage stream upload/download rather than full load to memory. With those you won't be having such issues.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!