재개 가능한 미디어 다운로드
컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
서버에서 대용량 미디어 파일을 다운로드할 때는 재개 가능한 미디어 다운로드를 호출하여 파일을 청크별로 다운로드합니다. Google API 생성된 라이브러리에 재개 가능한 함수와 상호작용하기 위한 편의 메서드가 포함되어 있음 미디어 다운로드
재개 가능한 미디어 다운로드 프로토콜은 재개 가능한 미디어 업로드와 유사합니다. 프로토콜에 대해 자세히 알아보려면 Google Drive API 문서
구현 세부정보
주요 관심 클래스는 MediaHttpDownloader 및 MediaHttpDownloaderProgressListener입니다. 미디어 콘텐츠가 청크로 다운로드되며 청크 크기를 구성할 수 있습니다. 만약 요청에 서버 오류가 발생하면 요청이 재시도됩니다.
서비스별로 생성된 라이브러리의 메서드가 검색 문서를 선택한 다음 편리한 다운로드 방법이 생성됩니다. OutputStream을 가져올 수도 있습니다. (Google API 검색 서비스와 함께 미디어 다운로드를 사용하는 방법에 대한 자세한 내용은 미디어 다운로드).
예를 들면 다음과 같습니다.
class CustomProgressListener implements MediaHttpDownloaderProgressListener { public void progressChanged(MediaHttpDownloader downloader) { switch (downloader.getDownloadState()) { case MEDIA_IN_PROGRESS: System.out.println(downloader.getProgress()); break; case MEDIA_COMPLETE: System.out.println("Download is complete!"); } } } OutputStream out = new FileOutputStream("/tmp/driveFile.jpg"); DriveFiles.Get request = drive.files().get(fileId); request.getMediaHttpDownloader().setProgressListener(new CustomProgressListener()); request.executeMediaAndDownloadTo(out);
서비스별로 생성된 라이브러리 없이도 이 기능을 사용할 수 있습니다. 예를 들면 다음과 같습니다.
OutputStream out = new FileOutputStream("/tmp/Test.jpg"); MediaHttpDownloader downloader = new MediaHttpDownloader(transport, httpRequestInitializer); downloader.setProgressListener(new CustomProgressListener()); downloader.download(requestUrl, out);
재개 가능한 미디어 다운로드는 기본적으로 사용 설정되어 있지만 사용 중지하고 대신 미디어 직접 다운로드를 사용합니다(예: 작은 파일을 다운로드하는 경우). 직접 미디어 다운로드는 1.9.0-beta Google API 클라이언트 라이브러리 버전입니다.
직접 미디어 다운로드는 단일 HTTP 요청으로 전체 미디어 콘텐츠를 반면에 재개 가능한 미디어 다운로드 프로토콜은 여러 형식으로 다운로드할 수 있고 요청을 처리합니다 직접 다운로드를 하면 HTTP 요청 수가 줄어들지만 발생할 수 있는 장애 (예: 연결 실패)의 가능성을 높입니다. 대용량 다운로드에 적합합니다
사용법은 위에 설명된 것과 동일하고 다음 항목이 추가됩니다. 호출로 MediaHttpDownloader 직접 다운로드를 하려면 다음 단계를 따르세요.
mediaHttpDownloader.setDirectDownloadEnabled(true);
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eDownload large files efficiently with resumable media download, splitting the process into smaller chunks.\u003c/p\u003e\n"],["\u003cp\u003eUtilize the \u003ccode\u003eMediaHttpDownloader\u003c/code\u003e and \u003ccode\u003eMediaHttpDownloaderProgressListener\u003c/code\u003e classes for managing and monitoring downloads.\u003c/p\u003e\n"],["\u003cp\u003eCustomize the download process by implementing a progress listener to track download state and progress.\u003c/p\u003e\n"],["\u003cp\u003eOpt for direct media download for smaller files, combining the download into a single HTTP request.\u003c/p\u003e\n"],["\u003cp\u003eResumable media download is enabled by default, but direct download can be activated using \u003ccode\u003emediaHttpDownloader.setDirectDownloadEnabled(true)\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["When you download a large media file from a server, use\n*resumable media download* to download the file chunk by chunk. The Google API\ngenerated libraries contain convenience methods for interacting with resumable\nmedia download.\n\nThe resumable media download protocol is similar to the resumable media upload\nprotocol, which is described in the\n[Google Drive API documentation](https://developers.google.com/drive/web/manage-uploads#resumable).\n\nImplementation details\n\nThe main classes of interest are [MediaHttpDownloader](https://googleapis.dev/java/google-api-client/latest/com/google/api/client/googleapis/media/MediaHttpDownloader.html) and [MediaHttpDownloaderProgressListener](https://googleapis.dev/java/google-api-client/latest/com/google/api/client/googleapis/media/MediaHttpDownloaderProgressListener.html).\nMedia content is downloaded in chunks, and chunk size is configurable. If a\nserver error is encountered in a request, then the request is retried.\n\nIf methods in the service-specific generated libraries support download in the\n[Discovery document](https://developers.google.com/discovery/v1/using), then a\nconvenient download method is created for these methods that takes in an\n[OutputStream](http://docs.oracle.com/javase/1.5.0/docs/api/org/omg/CORBA/portable/OutputStream.html).\n(For more about using media download with the Google APIs Discovery Service, see\n[Media download](https://developers.google.com/discovery/v1/using#discovery-doc-methods-mediadownload).)\n\nFor example: \n\n class CustomProgressListener implements MediaHttpDownloaderProgressListener {\n public void progressChanged(MediaHttpDownloader downloader) {\n switch (downloader.getDownloadState()) {\n case MEDIA_IN_PROGRESS:\n System.out.println(downloader.getProgress());\n break;\n case MEDIA_COMPLETE:\n System.out.println(\"Download is complete!\");\n }\n }\n }\n\n OutputStream out = new FileOutputStream(\"/tmp/driveFile.jpg\");\n\n DriveFiles.Get request = drive.files().get(fileId);\n request.getMediaHttpDownloader().setProgressListener(new CustomProgressListener());\n request.executeMediaAndDownloadTo(out);\n\nYou can also use this feature without service-specific generated libraries.\nHere is an example: \n\n OutputStream out = new FileOutputStream(\"/tmp/Test.jpg\");\n\n MediaHttpDownloader downloader = new MediaHttpDownloader(transport, httpRequestInitializer);\n downloader.setProgressListener(new CustomProgressListener());\n downloader.download(requestUrl, out);\n\nDirect media download\n\nResumable media download is enabled by default, but you can disable it and use\ndirect media download instead, for example if you are downloading a small file.\nDirect media download was introduced in the\n[1.9.0-beta](http://google-api-java-client.blogspot.com/2012/05/version-190-beta-released.html)\nversion of the Google API Client Library for Java.\n\nDirect media download downloads the whole media content in one HTTP request, as\nopposed to the resumable media download protocol, which can download in multiple\nrequests. Doing a direct download reduces the number of HTTP requests but\nincreases the chance of failures (such as connection failures) that can happen\nwith large downloads.\n\nThe usage is the same as what is described above, plus the following\ncall that tells\n[MediaHttpDownloader](https://googleapis.dev/java/google-api-client/latest/com/google/api/client/googleapis/media/MediaHttpDownloader.html)\nto do direct downloads: \n\n mediaHttpDownloader.setDirectDownloadEnabled(true);"]]