Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of memory exception on multipart #106

Closed
wdayanand opened this issue Oct 10, 2017 · 3 comments
Closed

Out of memory exception on multipart #106

wdayanand opened this issue Oct 10, 2017 · 3 comments

Comments

@wdayanand
Copy link

I used volley for upload video it works if file size is small like 5 mb but if I try with large file it giving OOM exception .
Please help how I can upload large files with volley

@wdayanand
Copy link
Author

@OverRide
public byte[] getBody() throws AuthFailureError {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);

    try {
        // populate text payload
        Map<String, String> params = getParams();
        if (params != null && params.size() > 0) {
            textParse(dos, params, getParamsEncoding());
        }

        // populate data byte payload
        Map<String, DataPart> data = getByteData();
        if (data != null && data.size() > 0) {
            dataParse(dos, data);
        }

        // close multipart form data after text and file data
        dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

        return bos.toByteArray();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

========================$$
It crashed on= return bos.toByteArray()

@jpd236
Copy link
Collaborator

jpd236 commented Oct 10, 2017

I'm afraid Volley's architecture is such that it is not really built for large requests/responses. It 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. This is noted in the documentation, mostly for downloads but also affecting large uploads:

"Volley is not suitable for large download or streaming operations, since Volley holds all responses in memory during parsing"

I recommend using a different library/paradigm for this use case that doesn't try to load the full video in memory and which supports resumable uploads.

@jpd236 jpd236 closed this as completed Oct 10, 2017
@wdayanand
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants