我经历了很多参考(包括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?
如果存在,我需要解决方案,thnx