Stay organized with collections
Save and categorize content based on your preferences.
The following sample shows how to retrieve a note and its attachment:
REST
Call media.download() with the
name of the attachment download and the alt=media URL parameter. The
alt=media URL parameter tells the server that a download of content is
being requested.
To get the name of the attachment, you must first retrieve the note.
Java
/** * 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);}}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-19 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()`."]]],[]]