नोट और अटैचमेंट वापस पाना

नीचे दिए गए सैंपल में, नोट और उसके अटैचमेंट को वापस पाने का तरीका बताया गया है:

आराम

media.download() को अटैचमेंट डाउनलोड करने के नाम और alt=media यूआरएल पैरामीटर के साथ कॉल करें. alt=media यूआरएल पैरामीटर सर्वर को बताता है कि कॉन्टेंट को डाउनलोड करने का अनुरोध किया जा रहा है.

अटैचमेंट का नाम पाने के लिए, आपको पहले नोट वापस पाना होगा.

Java

/**
 * Gets and downloads the attachment of a note.
 *
 * @param note The note whose attachment will be downloaded.
 * @throws IOException
 */
private void getNoteAttachment(Note note) throws IOException {
  // First call is to get the attachment resources on the note.
  List<Attachment> attachments =
      keepService.notes().get(note.getName()).execute().getAttachments();

  if (!attachments.isEmpty()) {
    Attachment attachment = attachments.get(0);
    String mimeType = attachment.getMimeType().get(0);
    // A second call is required in order to download the attachment with the specified mimeType.
    OutputStream outputStream = new FileOutputStream("attachmentFile." + mimeType.split("/")[1]);
    keepService
        .media()
        .download(attachment.getName())
        .setMimeType(mimeType)
        .executeMediaAndDownloadTo(outputStream);
  }
}