首页 文章

uploadFileTask到QuickBlox时不允许的方法(405) - (Android)

提问于
浏览
1

我的问题是我使用 QBContent.uploadFileTask(file, true, null, new QBEntityCallback() 将文件上传到QuickBlox . 但我登陆 onError(List list) . 请检查图片 .

  • 这是我进入OnError方法:
    enter image description here

  • 在Logcat中显示:
    enter image description here

这是我的代码:

protected void startLoadAttachAudio(final file file){Handler h = new Handler(Looper.getMainLooper()); h.post(new Runnable(){public void run(){

QBContent.uploadFileTask(file, true, null, new QBEntityCallback<QBFile>() {
            @Override
            public void onSuccess(QBFile qbFile, Bundle bundle) {
                System.out.println("Success");
            }

            @Override
            public void onSuccess() {
                System.out.println("Success2");
            }

            @Override
            public void onError(List<String> list) {
                System.out.println("Failed.");

            }
        });
    }//end of run
}); //end of handler

}

2 回答

  • 0

    您可以使用库上传文件,我使用的是android async http . 例如:

    public void UploadFile(CarrierFileInformation carrierFileInformation)
    {
        String path = carrierFileInformation.GetSaveDir();
        File file = new File(path);
        if(!file.exists())
        {
            this.uploadedFile = true;
            Toast.makeText(this.activity, this.activity.getResources().getString(R.string.not_found_file), Toast.LENGTH_LONG).show();
            return;
        }
        String link = Settings.DOMAIN + MethodNames.UPLOAD_FILE;
        RequestParams requestParams = new RequestParams();
        try
        {
            requestParams.put(FieldNames.UPLOAD_FILE, file);
            requestParams.put(FieldNames.ORDER_ID, carrierFileInformation.GetOrderId());
            requestParams.put(FieldNames.TEST_ID, carrierFileInformation.GetTestId());
            requestParams.put(FieldNames.TEST_DETAIL_ID, carrierFileInformation.GetTestDetailId());
            requestParams.put(FieldNames.FLAG, carrierFileInformation.GetFlag());
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(link, requestParams, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                Log.e("t", "işlem tamam");
                uploadedFile = true;
            }
    
            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                uploadedFile = false;
            }
        });
    }
    

    requestParams用于发送params你的webservice,文件你知道你的文件 . 你可以编辑我的功能 .

    在build.gradle中,你必须在依赖bloc然后同步中添加此代码编译'com.loopj.android:android-async-http:1.4.9' .

  • 0

    我通过更新Quickblox的SDK版本自己解决了这个问题

相关问题