Onedrive api上传文件

问题描述 投票:2回答:1

我经历了很多参考(包括onedrive api doc),但是我无法使用okhttp请求将文件上传到onedrive。

以下是我尝试的代码:

    try {

            boolean status;

            String url = String.format("onedrive.live.com/v1.0/drive/root:/"+step.file_name+":/content"); 
//exceptions are not coming if i mention https:// in the url. but no output is coming

            Request request = new Request.Builder()
                    .url(url)
                    .put(RequestBody.create(MediaType.parse(step.getContent_type()),step.getFile_data()))
                    .addHeader("Authorization", String.format("Bearer %s",step.getAccess_token()))
                    .build();

            OkHttpClient okHttpClient = new OkHttpClient();


                Response response = okHttpClient.newCall(request).execute();

                status = response.code()==200 ? true : false;

            } catch (Exception e) {
                e.printStackTrace();
                return StepStatus.FAILURE;
            }

当尝试使用URL“ onedrive.live.com/v1.0/drive/root:/abc.txt:/content”从邮递员尝试时(PUT映射),它正在重定向到驱动器,但说该文件可能已删除。

但是,当我尝试生成带有文件名的url并点击驱动器时,它显示成功,但文件未保存/上传到驱动器中。

如何从okhttp请求将文件上传到onedrive?

java file-upload okhttp onedrive okhttp3
1个回答
0
投票

如果存在,我需要解决方案,thnx

© www.soinside.com 2019 - 2024. All rights reserved.