Aeolun / ts-jira-client

A Typescript wrapper for the Jira Rest API
https://aeolun.github.io/ts-jira-client/
MIT License
6 stars 2 forks source link

addAttachmentOnIssue It only accepts Buffer, but I would like Stream #2

Open Batyodie opened 6 months ago

Batyodie commented 6 months ago

The method for adding files to issue only accepts a buffer, this is not very convenient, I want to get a preview of the file in jira and its type, but it turns out that I won't be able to send it.

  /** Add attachment to a Issue
   * [Jira Doc](https://docs.atlassian.com/jira/REST/latest/#api/2/issue/{issueIdOrKey}/attachments-addAttachment)
   * @param issueId - issue id
   * @param readStream - readStream object from fs
   */
  addAttachmentOnIssue(issueId: string, readStream: Buffer) {
    const formData = new FormData();
    formData.append("file", new Blob([readStream], { type: "application/octet-stream" }));
    return this.doRequest<unknown>(
      this.makeRequestHeader(
        this.makeUri({
          pathname: `/issue/${issueId}/attachments`,
        }),
        {
          method: "POST",
          headers: {
            "X-Atlassian-Token": "nocheck",
          },
          data: formData,
        },
      ),
    );
  }

In the classic version of the library it is possible to send streams, as far as I know, this is due to the fact that they use postman instead of axios.

Снимок экрана 2024-03-31 в 14 03 36

For me, the most important thing is that you can transfer the name and type of the file.

Aeolun commented 2 months ago

@Batyodie New version should have two extra parameters that take both mimeType and fileName, which I think do what you want.