VolleyPlus icon indicating copy to clipboard operation
VolleyPlus copied to clipboard

SimpleMultipartRequest always returns octet-stream file extension

Open vikasgrover33 opened this issue 9 years ago • 6 comments

I am working with an android application where I am trying to upload a file to server with SimpleMultipartRequest, either I upload the jpeg,pdf,png but i always receive xyz.octet-stream file path in response. Even if I add some extra parameter. Below is the code for the same.

SimpleMultiPartRequest request = new SimpleMultiPartRequest(methodType, url, new Response.Listener<String>() {

        @Override
        public void onResponse(String s) {

            uploadSettable.set(s);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {

            uploadSettable.setException(volleyError);
        }
    }) {

        @Override
        public Map<String, String> getFilesToUpload() {
            Map<String, String> map = new HashMap<>();
            map.put("FileData", filePath);
            return map;
        }


        @Override
        public Map<String, MultiPartParam> getMultipartParams() {

            HashMap<String, MultiPartParam> stringMultiPartParamHashMap = new HashMap<>();
            stringMultiPartParamHashMap.put("Content-Type",new MultiPartParam("Content-Type","image/jpeg"));

            return super.getMultipartParams();
        }

        @Override
        public int getMethod() {
            return Method.POST;
        }


        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {

            Map headerMap = new HashMap();
            headerMap.put(ServiceConfig.AUTHORIZATION_KEY, ServiceConfig.BEARER_KEY + SharedPrefUtil.getAccessToken(
                    ServiceConfig.ACCESS_TOKEN_KEY, KeyConstants.SHARED_PREF_DEFAULT_VALUE, DoctorApplicationClass.getInstance().getBaseContext()));
            return headerMap;
        }

        @Override
        public void onProgress(final long transferredBytes, final long totalSize) {

            fileSize = totalSize;

            super.onProgress(transferredBytes, totalSize);

            new Thread(new Runnable() {

                @Override
                public void run() {

                    if (progressBarStatus < totalSize) {

                        progressBarStatus = (int) ((transferredBytes * 100) / totalSize);
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        progressBarHandler.post(new Runnable() {
                            public void run() {
                                progressBar.setProgress(progressBarStatus);
                            }
                        });

                    }

                    if (progressBarStatus >= totalSize) {

                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        progressBar.dismiss();

                    }
                }
            }).start();
        }
    };

vikasgrover33 avatar Dec 12 '15 09:12 vikasgrover33

No Response till now for the above issue.

vikasgrover33 avatar Jan 07 '16 11:01 vikasgrover33

This is the bug in SimpleMultiPartRequest where response always return with .octet.stream.

vikasgrover33 avatar Jan 12 '16 09:01 vikasgrover33

Facing similar issue. Trying to upload a Jpeg Image but it's content type is set to application/octet-stream which server blocks from uploading. It should be an image/jpeg type instead

smr.addFile("filePic", getPath(imageUri));

dotjavafile avatar Dec 29 '17 23:12 dotjavafile

yes, i have the same problem, its octet-stream always

scsonic avatar Mar 31 '18 07:03 scsonic

I solved this problem by changing the content-type in lib itself.

Thanks & Regards Vikas Grover +917503298590

On Sat, Mar 31, 2018 at 1:05 PM, scsonic [email protected] wrote:

yes, i have the same problem, its octet-stream always

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DWorkS/VolleyPlus/issues/40#issuecomment-377673737, or mute the thread https://github.com/notifications/unsubscribe-auth/APLxnusR7PcpWZr9pk0gQZOT2mLCf5HIks5tjzHfgaJpZM4G0FhT .

vikasgrover33 avatar Mar 31 '18 10:03 vikasgrover33

@vikasgrover33 How do you do that?

mehdii08 avatar Mar 22 '20 14:03 mehdii08