DWorkS / VolleyPlus

🏐 Volley library : make everything faster . Its an improvements for Volley by Google for Android https://android.googlesource.com/platform/frameworks/volley
https://github.com/DWorkS/VolleyPlus
984 stars 274 forks source link

SimpleMultipartRequest always returns octet-stream file extension #40

Open vikasgrover33 opened 8 years ago

vikasgrover33 commented 8 years ago

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() {

        @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 commented 8 years ago

No Response till now for the above issue.

vikasgrover33 commented 8 years ago

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

dotjavafile commented 6 years ago

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));

scsonic commented 6 years ago

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

vikasgrover33 commented 6 years ago

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 notifications@github.com 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 .

mehdii08 commented 4 years ago

@vikasgrover33 How do you do that?