I am using GDAA
in my application for managing my application files in google drive. All the below listed operations work fine like
- google sign-in (scope is added for AppData Folder)
- download file from
AppData Folder
- upload file to
AppData Folder
- delete file from
AppData Folder
but when I try to overwrite a file in AppData Folder
i am getting the following error in the onResult()
callback.
Status Message : Failed to commit changes.
Status Code : INTERNAL_ERROR (8)
I am unable to understand why this is happening. Please find below my code for reference
public void overwrite(String strLocalFilePath, String strDriveId, String strGoogleDriveFileMimeType, String strGoogleDriveFileTitle){
final DriveId driveId = DriveId.decodeFromString(strDriveId);
DriveFile file = driveId.asDriveFile();
file.open(mGoogleApiClient, DriveFile.MODE_WRITE_ONLY, null).setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
Log.e(TAG,"Error");
return;
}
DriveContents driveContents = result.getDriveContents();
OutputStream outputStream = driveContents.getOutputStream();
boolean isSuccess = writeFileToStream(outputStream, strLocalFilePath);
if (isSuccess) {
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle(strGoogleDriveFileTitle)
.setMimeType(strGoogleDriveFileMimeType)
.build();
ExecutionOptions executionOptions = new ExecutionOptions.Builder()
.setNotifyOnCompletion(true)
.setTrackingTag("SAMPLE_TRACKING_TAG")
.build();
driveContents.commit(mGoogleApiClient, changeSet, executionOptions).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
// Handle the response status
if (!status.getStatus().isSuccess()) {
Log.e(TAG, "Error while trying to overwrite file. Message : "+status.getStatus().getStatusMessage() + " Status code : "+status.getStatus().getStatusCode());
return;
}else{
Log.d(TAG,"File overwritten successfully!!");
}
}
});
} else {
Log.e(TAG, "File I/O Error occurred : "+ strGoogleDriveFileTitle);
}
}
});
}
private boolean writeFileToStream (OutputStream oos, String filePath){
if (oos != null) {
InputStream is = null;
try {
Log.d(TAG, "Started writing file : "+filePath);
is = new FileInputStream(filePath);
byte[] buf = new byte[4096];
int c;
while ((c = is.read(buf, 0, buf.length)) > 0) {
oos.write(buf, 0, c);
oos.flush();
}
Log.d(TAG, "Finished writing file : "+filePath);
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
try {
if(oos != null) {
oos.close();
}
if(is != null){
is.close();
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}
return false;
}