java.lang.IllegalArgumentException:Base64编码的输入字符串的长度不是Cloudinary的4的倍数

时间:2017-09-13 04:42:16

标签: android base64 cloudinary

当我尝试上传文件时,我收到此消息。 " java.lang.IllegalArgumentException:Base64编码输入字符串的长度不是4的倍数。" 这是我的代码

我正在为我的CDN使用cloudinary android库。 通常,我的图书馆工作正常。但有时它会发生,我无法找出原因。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == ConstantsCustomGallery.REQUEST_CODE && resultCode == RESULT_OK && data != null) {
        //The array list has the image paths of the selected images
        images = data.getParcelableArrayListExtra(ConstantsCustomGallery.INTENT_EXTRA_IMAGES);

        imagePath = images.get(0).path;


        UploadCallback callback = new UploadCallback() {
            @Override
            public void onStart(String requestId) {

                Log.d("id", requestId);
                loading_layout.setVisibility(View.VISIBLE);
                loading.show();
                //progress_text.setVisibility(View.VISIBLE);

            }

            @Override
            public void onProgress(String requestId, long bytes, long totalBytes) {

                Log.d("pregress", String.valueOf(bytes/totalBytes * 100) + "%");
                final String progressString = String.valueOf(bytes/totalBytes * 100) + "%";
                //progress_text.setText(progressString);

            }

            @Override
            public void onSuccess(String requestId, Map resultData) {

                loading_layout.setVisibility(View.GONE);
                loading.hide();
                //progress_text.setVisibility(View.GONE);

                Log.d("resultdata", resultData.get("secure_url").toString());

                String uploadImg = resultData.get("secure_url").toString();
                String[] splitString = uploadImg.split("/");
                String uploadTarget = splitString[splitString.length-2] + "/" + splitString[splitString.length-1];
                String finalUploadTaget = FunctionBase.imageUrlBase300 + uploadTarget;

                finalImage = uploadTarget;

                RequestManager requestManager = Glide.with(getActivity());

                if(gifChecker(finalUploadTaget)){

                    requestManager
                            .load(finalUploadTaget)
                            .asGif()
                            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                            .into(preview);;

                } else {

                    requestManager.load(finalUploadTaget).into(preview);

                }

            }

            @Override
            public void onError(String requestId, ErrorInfo error) {

                Log.d("error1", error.toString());
                TastyToast.makeText(getActivity(), "업로드가 실패 했습니다 다시 시도해주세요.", TastyToast.LENGTH_LONG, TastyToast.ERROR);

            }

            @Override
            public void onReschedule(String requestId, ErrorInfo error) {

                Log.d("error2", error.toString());
                TastyToast.makeText(getActivity(), "업로드가 실패 했습니다 다시 시도해주세요.", TastyToast.LENGTH_LONG, TastyToast.ERROR);

            }
        };

        MediaManager.get().upload(imagePath).unsigned(AppConfig.image_preset).callback(callback).dispatch();







    }



}

下面的logcat有错误日志。

09-13 14:22:02.348 31605-32612/? E/JobExecutor: Crashed job{id=29, 
finished=true, result=FAILURE, canceled=false, periodic=false, class=UploadJob, tag=CLD}
                                            java.lang.IllegalArgumentException: Length of Base64 encoded input string is not a multiple of 4.
                                                at com.cloudinary.utils.Base64Coder.decode(Base64Coder.java:243)
                                                at com.cloudinary.utils.Base64Coder.decode(Base64Coder.java:226)
                                                at com.cloudinary.utils.Base64Coder.decode(Base64Coder.java:214)
                                                at com.cloudinary.utils.Base64Coder.decodeString(Base64Coder.java:181)
                                                at com.cloudinary.android.payload.FilePayload.loadData(FilePayload.java:51)
                                                at com.cloudinary.android.payload.PayloadFactory.fromUri(PayloadFactory.java:44)
                                                at com.cloudinary.android.DefaultRequestProcessor.processRequest(DefaultRequestProcessor.java:82)
                                                at com.cloudinary.android.MediaManager.processRequest(MediaManager.java:367)
                                                at com.cloudinary.android.AndroidJobStrategy$UploadJob.onRunJob(AndroidJobStrategy.java:203)
                                                at com.evernote.android.job.Job.runJob(Job.java:109)
                                                at com.evernote.android.job.JobExecutor$JobCallable.runJob(JobExecutor.java:151)
                                                at com.evernote.android.job.JobExecutor$JobCallable.call(JobExecutor.java:136)
                                                at com.evernote.android.job.JobExecutor$JobCallable.call(JobExecutor.java:119)
                                                at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                at java.lang.Thread.run(Thread.java:818)
09-13 14:22:02.348 31605-32613/? E/JobExecutor: Crashed job{id=30, finished=true, result=FAILURE, canceled=false, periodic=false, class=UploadJob, tag=CLD}
                                            java.lang.IllegalArgumentException: Length of Base64 encoded input string is not a multiple of 4.
                                                at com.cloudinary.utils.Base64Coder.decode(Base64Coder.java:243)
                                                at com.cloudinary.utils.Base64Coder.decode(Base64Coder.java:226)
                                                at com.cloudinary.utils.Base64Coder.decode(Base64Coder.java:214)
                                                at com.cloudinary.utils.Base64Coder.decodeString(Base64Coder.java:181)
                                                at com.cloudinary.android.payload.FilePayload.loadData(FilePayload.java:51)
                                                at com.cloudinary.android.payload.PayloadFactory.fromUri(PayloadFactory.java:44)
                                                at com.cloudinary.android.DefaultRequestProcessor.processRequest(DefaultRequestProcessor.java:82)
                                                at com.cloudinary.android.MediaManager.processRequest(MediaManager.java:367)
                                                at com.cloudinary.android.AndroidJobStrategy$UploadJob.onRunJob(AndroidJobStrategy.java:203)
                                                at com.evernote.android.job.Job.runJob(Job.java:109)
                                                at com.evernote.android.job.JobExecutor$JobCallable.runJob(JobExecutor.java:151)
                                                at com.evernote.android.job.JobExecutor$JobCallable.call(JobExecutor.java:136)
                                                at com.evernote.android.job.JobExecutor$JobCallable.call(JobExecutor.java:119)
                                                at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                at java.lang.Thread.run(Thread.java:818)

0 个答案:

没有答案