Package com.google.api.client.googleapis.media

Examples of com.google.api.client.googleapis.media.MediaHttpUploader


          driveItem = service.files().insert(driveItem).execute();
        } else {
          final InputStreamContent params = new InputStreamContent(FILE, new ByteArrayInputStream(data));
          params.setLength(data.length);
          Insert inserter = service.files().insert(driveItem, params);
          MediaHttpUploader uploader = inserter.getMediaHttpUploader();
          prepareUploader(uploader, data);
          driveItem = inserter.execute();
        }
        if (driveItem == null) {
          throw new CloudsyncException("Could not create item '" + item.getPath() + "'");
View Full Code Here


          driveItem = service.files().update(item.getRemoteIdentifier(), driveItem).execute();
        } else {
          final InputStreamContent params = new InputStreamContent(FILE, new ByteArrayInputStream(data));
          params.setLength(data.length);
          Update updater = service.files().update(item.getRemoteIdentifier(), driveItem, params);
          MediaHttpUploader uploader = updater.getMediaHttpUploader();
          prepareUploader(uploader, data);
          driveItem = updater.execute();
        }
        if (driveItem == null) {
          throw new CloudsyncException("Could not update item '" + item.getPath() + "'");
View Full Code Here

            // Create an API request that specifies that the mediaContent
            // object is the thumbnail of the specified video.
            Set thumbnailSet = youtube.thumbnails().set(videoId, mediaContent);

            // Set the upload type and add an event listener.
            MediaHttpUploader uploader = thumbnailSet.getMediaHttpUploader();

            // Indicate whether direct media upload is enabled. A value of
            // "True" indicates that direct media upload is enabled and that
            // the entire media content will be uploaded in a single request.
            // A value of "False," which is the default, indicates that the
            // request will use the resumable media upload protocol, which
            // supports the ability to resume an upload operation after a
            // network interruption or other transmission failure, saving
            // time and bandwidth in the event of network failures.
            uploader.setDirectUploadEnabled(false);

            // Set the upload state for the thumbnail image.
            MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() {
                @Override
                public void progressChanged(MediaHttpUploader uploader) throws IOException {
                    switch (uploader.getUploadState()) {
                        // This value is set before the initiation request is
                        // sent.
                        case INITIATION_STARTED:
                            System.out.println("Initiation Started");
                            break;
                        // This value is set after the initiation request
                        //  completes.
                        case INITIATION_COMPLETE:
                            System.out.println("Initiation Completed");
                            break;
                        // This value is set after a media file chunk is
                        // uploaded.
                        case MEDIA_IN_PROGRESS:
                            System.out.println("Upload in progress");
                            System.out.println("Upload percentage: " + uploader.getProgress());
                            break;
                        // This value is set after the entire media file has
                        //  been successfully uploaded.
                        case MEDIA_COMPLETE:
                            System.out.println("Upload Completed!");
                            break;
                        // This value indicates that the upload process has
                        //  not started yet.
                        case NOT_STARTED:
                            System.out.println("Upload Not Started!");
                            break;
                    }
                }
            };
            uploader.setProgressListener(progressListener);

            // Upload the image and set it as the specified video's thumbnail.
            ThumbnailSetResponse setResponse = thumbnailSet.execute();

            // Print the URL for the updated video's thumbnail image.
View Full Code Here

            // The third argument is the actual video content.
            YouTube.Videos.Insert videoInsert = youtube.videos()
                    .insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent);

            // Set the upload type and add an event listener.
            MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();

            // Indicate whether direct media upload is enabled. A value of
            // "True" indicates that direct media upload is enabled and that
            // the entire media content will be uploaded in a single request.
            // A value of "False," which is the default, indicates that the
            // request will use the resumable media upload protocol, which
            // supports the ability to resume an upload operation after a
            // network interruption or other transmission failure, saving
            // time and bandwidth in the event of network failures.
            uploader.setDirectUploadEnabled(false);

            MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() {
                public void progressChanged(MediaHttpUploader uploader) throws IOException {
                    switch (uploader.getUploadState()) {
                        case INITIATION_STARTED:
                            System.out.println("Initiation Started");
                            break;
                        case INITIATION_COMPLETE:
                            System.out.println("Initiation Completed");
                            break;
                        case MEDIA_IN_PROGRESS:
                            System.out.println("Upload in progress");
                            System.out.println("Upload percentage: " + uploader.getProgress());
                            break;
                        case MEDIA_COMPLETE:
                            System.out.println("Upload Completed!");
                            break;
                        case NOT_STARTED:
                            System.out.println("Upload Not Started!");
                            break;
                    }
                }
            };
            uploader.setProgressListener(progressListener);

            // Call the API and upload the video.
            Video returnedVideo = videoInsert.execute();

            // Print data about the newly inserted video from the API response.
View Full Code Here

       */
      YouTube.Videos.Insert videoInsert = youtube.videos().insert(
          "snippet,statistics,status", video, mediaContent);

      // Set the upload type and add event listener.
      MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();
      uploader.setDirectUploadEnabled(false);

      MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() {
        @Override
        public void progressChanged(MediaHttpUploader uploader)
            throws IOException {
          switch (uploader.getUploadState()) {
          case INITIATION_STARTED:
            log.debug("Initiation Started");
            break;
          case INITIATION_COMPLETE:
            log.debug("Initiation Completed");
            break;
          case MEDIA_IN_PROGRESS:
            log.debug("Upload in progress");
            log.debug("Upload percentage: "
                + uploader.getProgress());
            break;
          case MEDIA_COMPLETE:
            log.debug("Upload Completed!");
            log.debug("Deleting local file...  "
                + videoFile.delete());
            break;
          case NOT_STARTED:
            log.debug("Upload Not Started!");
            break;
          }
        }
      };
      uploader.setProgressListener(progressListener);

      uploadedVideo = videoInsert.execute();
      String playListItemId = Playlists.insertItem(playListToken,
          uploadedVideo.getId());

View Full Code Here

            YouTube.Videos.Insert videoInsert = youtube.videos().insert(
                    "snippet,statistics,status", videoObjectDefiningMetadata,
                    mediaContent);

            // Set the upload type and add event listener.
            MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();

            /*
             * Sets whether direct media upload is enabled or disabled. True =
             * whole media content is uploaded in a single request. False
             * (default) = resumable media upload protocol to upload in data
             * chunks.
             */
            uploader.setDirectUploadEnabled(false);

            MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() {
                public void progressChanged(MediaHttpUploader uploader)
                        throws IOException {
                    switch (uploader.getUploadState()) {
                    case INITIATION_STARTED:
                        logger.info("Initiation Started");
                        break;
                    case INITIATION_COMPLETE:
                        logger.info("Initiation Completed");
                        break;
                    case MEDIA_IN_PROGRESS:
                        logger.info("Upload in progress");
                        logger.info("Upload percentage: "
                                + uploader.getProgress());
                        break;
                    case MEDIA_COMPLETE:
                        logger.info("Upload Completed!");
                        break;
                    case NOT_STARTED:
                        logger.info("Upload Not Started!");
                        break;
                    }
                }
            };
            uploader.setProgressListener(progressListener);

            // Execute upload.
            Video returnedVideo = videoInsert.execute();

            // Print out returned results.
View Full Code Here

TOP

Related Classes of com.google.api.client.googleapis.media.MediaHttpUploader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.