Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Im folgenden Beispiel wird gezeigt, wie eine Notiz und ihr Anhang abgerufen werden:
REST
Rufen Sie media.download() mit dem Namen des Anhangsdownloads und dem URL-Parameter alt=media auf.
Über den URL-Parameter alt=media wird dem Server mitgeteilt, dass ein Download von Inhalten angefordert wird.
Wenn Sie den Namen des Anhangs abrufen möchten, müssen Sie zuerst die Notiz abrufen.
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);}}
[null,null,["Zuletzt aktualisiert: 2025-03-11 (UTC)."],[],[],null,["# Retrieve notes and attachments\n\nThe following sample shows how to retrieve a note and its attachment: \n\n### REST\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\n### Java\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 }"]]