【发布时间】:2016-07-12 15:06:13
【问题描述】:
我在使用 java api 将文件上传到保管箱时遇到以下异常。
com.dropbox.core.DbxException$BadRequest: {"error": "OAuth 2 \"Authorization\" header is not well-formed."}
at com.dropbox.core.DbxRequestUtil.unexpectedStatus(DbxRequestUtil.java:207)
at com.dropbox.core.DbxClient$SingleUploader$1.handle(DbxClient.java:765)
at com.dropbox.core.DbxClient$SingleUploader$1.handle(DbxClient.java:761)
at com.dropbox.core.DbxRequestUtil.finishResponse(DbxRequestUtil.java:279)
at com.dropbox.core.DbxClient$SingleUploader.finish(DbxClient.java:761)
at com.dropbox.core.DbxClient.finishUploadFile(DbxClient.java:629)
at com.dropbox.core.DbxClient.uploadFile(DbxClient.java:562)
at com.dropbox.core.DbxClient.uploadFile(DbxClient.java:514)
以下是我的代码
public DbxClient authDropbox(String authAccessToken)throws IOException, DbxException {
DbxRequestConfig dbxRequestConfig = new DbxRequestConfig("JavaDropboxTutorial/1.0", Locale.getDefault().toString());
dbxClient = new DbxClient(dbxRequestConfig, authAccessToken);
return dbxClient;
}
public String uploadToDropbox(String filePath,String fileName,String folderName,DbxClient dbxClient) throws DbxException,IOException {
String sharedUrl;
File inputFile = new File(filePath);
FileInputStream fis = new FileInputStream(inputFile);
try {
dbxClient.uploadFile("/"+folderName+"/"+ fileName,DbxWriteMode.add(), inputFile.length(), fis);
sharedUrl = dbxClient.createShareableUrl("/"+folderName +"/"+fileName);
} finally {
fis.close();
}
return sharedUrl;
}
文件上传代码
【问题讨论】:
标签: dropbox-api