nylas/nylas-python

File.filename doesn't apply when type is stream:

Closed this issue · 0 comments

rcoh commented

Setting a filename on an attachment only works when using .data. When .stream is used, it falls back to the name of the file on the uploading system.

        myfile = self.nylas_client.files.create()
        myfile.content_type = 'application/pdf'
        myfile.filename = attachment_name
        with open(attachment_path, 'rb') as f:
            myfile.stream = f
            myfile.save()

        myfile.filename = attachment_name
        # Create a new draft
        draft = self.nylas_client.drafts.create()
        if type(recipients) == str:
            recipients = [recipients]
        draft.to = [{'email': recipient} for recipient in recipients]
        draft.subject = subject
        draft.body = message
        draft.attach(myfile)