OfficeDev / ews-java-api

A java client library to access Exchange web services. The API works against Office 365 Exchange Online as well as on premises Exchange.
MIT License
868 stars 559 forks source link

Getting an attachements #740

Open Cacus3 opened 3 years ago

Cacus3 commented 3 years ago

Hi, im trying to download an attachments but im stuck on example im docs.

im tried to use examlpe from https://docs.microsoft.com/en-us/office/dev/add-ins/outlook/get-attachments-of-an-outlook-item?view=outlook-js-preview and translate it to java. i got

 ExchangeService service = new ExchangeService();
         ExchangeCredentials credentials = new TokenCredentials(requset.attachmentToken);
         service.setCredentials(credentials);
         service.setUrl(new URI(requset.ewsUrl));

         String[] arr = (String[]) requset.attachmentsID.toArray();
         service.getAttachments(arr, null, new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent));

in docs service.getAttachments take array of string (ID's) but here a need to pass Attachment[] how to get an array of attachments before gets them from api?

Cacus3 commented 3 years ago

@yinaa can u help me with this?

moocstudent commented 3 years ago
  /**
   * Loads the content of the file attachment into the specified file.
   * Calling this method results in a call to EWS.
   *
   * @param fileName the file name
   * @throws Exception the exception
   */
  public void load(String fileName) throws Exception {
    File fileStream = new File(fileName);

    try {
      this.loadToStream = new FileOutputStream(fileStream);
      this.load();
      this.loadToStream.flush();
    } finally {
      IOUtils.closeQuietly(this.loadToStream);
      this.loadToStream = null;
    }

    this.fileName = fileName;
    this.content = null;
    this.contentStream = null;
  }

you can use this method at package microsoft.exchange.webservices.data.property.complex.FileAttachment;