use of org.odk.collect.android.exception.MultipleFoldersFoundException in project collect by opendatakit.
the class InstanceGoogleSheetsUploader method uploadMediaFile.
private String uploadMediaFile(File instanceFile, String fileName) throws UploadException {
String filePath = instanceFile.getParentFile() + "/" + fileName;
File toUpload = new File(filePath);
if (!new File(filePath).exists()) {
throw new UploadException(Collect.getInstance().getString(R.string.media_upload_error, filePath));
}
String folderId;
try {
folderId = driveHelper.createOrGetIDOfFolderWithName(jrFormId);
} catch (IOException | MultipleFoldersFoundException e) {
Timber.e(e);
throw new UploadException(e.getMessage());
}
String uploadedFileId;
// file is ready to be uploaded
try {
uploadedFileId = driveHelper.uploadFileToDrive(filePath, folderId, toUpload);
} catch (IOException e) {
Timber.e(e, "Exception thrown while uploading the file to drive");
throw new UploadException(e.getMessage());
}
// checking if file was successfully uploaded
if (uploadedFileId == null) {
throw new UploadException("Unable to upload the media files. Try again");
}
return getHyperlink(UPLOADED_MEDIA_URL + uploadedFileId, fileName);
}
Aggregations