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 2025-08-04 UTC."],[],[],null,["The following sample shows how to retrieve a note and its attachment: \n\nREST\n\nCall\n[`media.download()`](/workspace/keep/api/reference/rest/v1/media/download)\nwith the name of the attachment download and the `alt=media` URL parameter.\nThe `alt=media` URL parameter tells the server that a download of content is\nbeing requested.\n\nTo get the name of the attachment, you must first [retrieve the note](#note).\n| **Note:** The `alt=media` URL parameter is a [system parameter](https://cloud.google.com/apis/docs/system-parameters) available across all Google REST APIs. If you use a client library for the Google Keep API, you do not need to explicitly set this parameter.\n\nJava \n\n /**\n * Gets and downloads the attachment of a note.\n *\n * @param note The note whose attachment will be downloaded.\n * @throws IOException\n */\n private void getNoteAttachment(Note note) throws IOException {\n // First call is to get the attachment resources on the note.\n List\u003cAttachment\u003e attachments =\n keepService.notes().get(note.getName()).execute().getAttachments();\n\n if (!attachments.isEmpty()) {\n Attachment attachment = attachments.get(0);\n String mimeType = attachment.getMimeType().get(0);\n // A second call is required in order to download the attachment with the specified mimeType.\n OutputStream outputStream = new FileOutputStream(\"attachmentFile.\" + mimeType.split(\"/\")[1]);\n keepService\n .media()\n .download(attachment.getName())\n .setMimeType(mimeType)\n .executeMediaAndDownloadTo(outputStream);\n }\n }"]]