Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

509
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda