메모 및 첨부파일 가져오기

다음 샘플은 메모와 첨부파일을 가져오는 방법을 보여줍니다.

REST

첨부파일 다운로드 이름과 alt=media URL 매개변수를 사용하여 media.download()를 호출합니다. alt=media URL 매개변수는 콘텐츠 다운로드가 요청되고 있음을 서버에 알립니다.

첨부파일 이름을 확인하려면 먼저 메모를 검색해야 합니다.

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);
  }
}