Java Code Examples for com.google.api.services.drive.model.File#getDownloadUrl()

The following examples show how to use com.google.api.services.drive.model.File#getDownloadUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoteGoogleDriveConnector.java    From cloudsync with GNU General Public License v2.0 6 votes vote down vote up
@Override
public InputStream get(final Handler handler, final Item item) throws CloudsyncException
{
	initService(handler);

	int retryCount = 0;
	do
	{
		try
		{
			refreshCredential();

			final File driveItem = _getDriveItem(item);
			final String downloadUrl = driveItem.getDownloadUrl();
			final HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
			return resp.getContent();
		}
		catch (final IOException e)
		{
			retryCount = validateException("remote get", item, e, retryCount);
			if(retryCount < 0) // TODO workaround - fix this later
				retryCount = 0;
		}
	}
	while (true);
}
 
Example 2
Source File: DriveSyncService.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(Entry entry) {
    LogUtil.log(getClass().getSimpleName(), "delete()");

    SyncInfo info = new SyncInfo();
    info.setTitle(entry.uuid);
    info.setSyncService(SyncService.GoogleDrive.ordinal());
    info.setModifiedDate(Calendar.getInstance(Locale.getDefault()).getTimeInMillis());
    info.setSyncStatus(SyncStatus.DELETE);
    SyncInfoDao.saveData(info);

    File file = getEntry(entry.uuid);

    if (file != null && file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
        try {
            service.files().delete(file.getId()).execute();

            info.setSyncStatus(SyncStatus.OK);
            SyncInfoDao.saveData(info);

        } catch (IOException e) {
            // An error occurred.
            e.printStackTrace();
            if (!BuildConfig.DEBUG) Crashlytics.logException(e);
        }
    } else {
        LogUtil.log(getClass().getSimpleName(), "file == null: " + (file == null));
        if (!BuildConfig.DEBUG) Crashlytics.log("file == null in DriveSyncService#delete(Entry): " + (file == null));

        info.setSyncStatus(SyncStatus.OK);
        SyncInfoDao.saveData(info);
    }
}
 
Example 3
Source File: DriveSyncService.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean delete(Photo photo) {
    LogUtil.log(getClass().getSimpleName(), "delete(Photo)");

    SyncInfo info = new SyncInfo();
    info.setTitle(photo.name.toUpperCase());
    info.setSyncService(SyncService.GoogleDrive.ordinal());
    info.setModifiedDate(Calendar.getInstance(Locale.getDefault()).getTimeInMillis());
    info.setSyncStatus(SyncStatus.DELETE);
    SyncInfoDao.saveData(info);

    File file = getPhoto(photo.name);

    if (file != null && file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
        try {
            service.files().delete(file.getId()).execute();

            info.setSyncStatus(SyncStatus.OK);
            SyncInfoDao.saveData(info);

            return true;

        } catch (IOException e) {
            // An error occurred.
            e.printStackTrace();
            if (!BuildConfig.DEBUG) Crashlytics.logException(e);
            return false;
        }
    } else {
        LogUtil.log(getClass().getSimpleName(), "file == null: " + (file == null));
        if (!BuildConfig.DEBUG) Crashlytics.log("file == null in DriveSyncService#delete(Photo): " + (file == null));

        info.setSyncStatus(SyncStatus.OK);
        SyncInfoDao.saveData(info);

        return true;
    }
}
 
Example 4
Source File: DriveSyncService.java    From narrate-android with Apache License 2.0 4 votes vote down vote up
@Override
public Entry download(String uuid) {
    LogUtil.log(getClass().getSimpleName(), "download()");

    File file = getEntry(uuid);

    if (file != null && file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
        try {
            HttpResponse resp =
                    service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl()))
                            .execute();

            ByteArrayOutputStream os = new ByteArrayOutputStream();
            resp.download(os);
            LogUtil.log(getClass().getSimpleName(), "Download: " + os.toString("UTF-8"));

            // process input stream
            Entry entry = EntryHelper.fromJson(os.toString("UTF-8"));

            // close stream to prevent a memory leak
            os.close();

            if (entry != null) {
                LogUtil.log(getClass().getSimpleName(), "entry != null");
                SyncInfo info = new SyncInfo();
                info.setTitle(entry.uuid);
                info.setSyncService(SyncService.GoogleDrive.ordinal());
                info.setModifiedDate(Calendar.getInstance(Locale.getDefault()).getTimeInMillis());
                info.setSyncStatus(SyncStatus.OK);
                info.setRevision(String.valueOf(file.getVersion()));
                SyncInfoDao.saveData(info);
            } else
                LogUtil.log(getClass().getSimpleName(), "entry == null");

            return entry;

        } catch (Exception e) {
            LogUtil.log(getClass().getSimpleName(), "Exception in download() - " + e.getMessage());
            if (!BuildConfig.DEBUG) Crashlytics.logException(e);
        }
    } else {
        LogUtil.log(getClass().getSimpleName(), "file == null: " + (file == null));
        if (!BuildConfig.DEBUG) Crashlytics.log("file == null in DriveSyncService#download(Entry): " + (file == null));
    }

    return null;
}