Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
L'exemple suivant montre comment récupérer une note et sa pièce jointe:
REST
Appelez media.download() avec le nom du téléchargement de l'attachement et le paramètre d'URL alt=media.
Le paramètre d'URL alt=media indique au serveur qu'un téléchargement de contenu est demandé.
Pour obtenir le nom de la pièce jointe, vous devez d'abord récupérer la 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);}}
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/03/11 (UTC).
[null,null,["Dernière mise à jour le 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 }"]]