/**
* Gets and downloads the attachment of a note.
*
* @param note The note whose attachment will be downloaded.
* @throws IOException
*/
private void getNoteAttachment(Note note) throws IOException {
// First call is to get the attachment resources on the note.
List<Attachment> attachments =
keepService.notes().get(note.getName()).execute().getAttachments();
if (!attachments.isEmpty()) {
Attachment attachment = attachments.get(0);
String mimeType = attachment.getMimeType().get(0);
// A second call is required in order to download the attachment with the specified mimeType.
OutputStream outputStream = new FileOutputStream("attachmentFile." + mimeType.split("/")[1]);
keepService
.media()
.download(attachment.getName())
.setMimeType(mimeType)
.executeMediaAndDownloadTo(outputStream);
}
}
[[["이해하기 쉬움","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"]],["최종 업데이트: 2024-12-01(UTC)"],[[["Retrieve a note's attachment by calling `media.download()` with the attachment's name and the `alt=media` URL parameter, which signals a content download request."],["To obtain the attachment's name, you need to first retrieve the note itself using the `notes().get()` method."],["For Java, you need to make two calls: one to get the attachment resources and another to download the attachment with the specified MIME type using `media().download()`."]]],[]]