Open efreethy opened 3 years ago
@randyho-kk that's the wrong API :) This library uses v2 of the JIRA api.
I'd also really like the ability add an attachment, and a method exists for (addAttachementToIssue
- https://github.com/jira-node/node-jira-client/blob/master/src/jira.js#L1559).
Unfortunately I don't have the file on the FS (and I don't intend to put it there) and I can't get it work by turning a string into a stream, eg.
Readable = require('stream').Readable
...
# standard Jira setup, known to work because I do a bunch of other stuff just fine
...
var message = 'this should work :(';
Jira.addAttachmentOnIssue(issue.id, Readable.from(message));
This gets me a 500 error from the server due to EOF
java.lang.RuntimeException: org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
Followed by a standard java stack trace, not so useful in this context. I'm on a version of node where this should work
# node --version
v16.18.1
FWIW in another project I have successfully added attachments using the servicedesk API (/rest/servicedeskapi/request/#{id}/attachment
), but I built the request myself - I'd like to avoid that if possible.
Edit: this actually works if you use fs.getReadStream('/path/to/file');
so there's something different about this stream than that created by Readable.from
:(
Solved by adding a path
property to the created stream which appears to be used as the filename of the attachment in JIRA.
Readable = require('stream').Readable
...
# standard Jira setup
...
var message = 'this now works, yay, and :(';
var stream = Readable.from(message);
stream.path = 'file-name-in-jira.ext';
Jira.addAttachmentOnIssue(issue.id, stream);
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post