我正在尝试使用适用于Android的Live SDK上传到One Drive,每次都会将“null”作为例外。
这是我的代码:
public void createFile(){
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{
String fileName = "UploadTest.txt";
String filePath = Environment.getExternalStorageDirectory().toString() + File.separator + fileName;
File file = new File(filePth);
try {
final FileInputStream is = new FileInputStream(file);
client.uploadAsync("me/skydrive",file.getName(), is, new LiveUploadOperationListener() {
public void onUploadFailed(LiveOperationException exception, LiveOperation operation) {
Log.e("OneDrive","Error uploading file 1: " + exception.getMessage() );
}
public void onUploadCompleted(LiveOperation operation) {
Log.e("OneDrive","File uploaded.");
try {
is.close();
} catch (IOException ioe) {
Log.e("OneDrive","Error uploading file 2: " + ioe.getMessage());
}
}
public void onUploadProgress(int totalBytes, int bytesRemaining, LiveOperation operation) {
}
});
} catch (IOException ioex) {
Log.e("OneDrive","Error uploading file 3: " + ioex.getMessage());
return;
} catch (Exception ex) {
Log.e("OneDrive","Error uploading file 4: " + ex.getMessage());
return;
}
}
});
t.start();
}
日志报告:
Error uploading file 4:null
我正在尝试上传到根目录。
请帮助,谢谢。
答案 0 :(得分:1)
代码完美无缺。客户端实例化存在一些问题,在实例化时必须注意。