/** * Gets and downloads the attachment of a note. * * @param note The note whose attachment will be downloaded. * @throws IOException */privatevoidgetNoteAttachment(Notenote)throwsIOException{// First call is to get the attachment resources on the note.List<Attachment>attachments=keepService.notes().get(note.getName()).execute().getAttachments();if(!attachments.isEmpty()){Attachmentattachment=attachments.get(0);StringmimeType=attachment.getMimeType().get(0);// A second call is required in order to download the attachment with the specified mimeType.OutputStreamoutputStream=newFileOutputStream("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"]],["最后更新时间 (UTC):2024-12-21。"],[[["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()`."]]],[]]