@@ -969,7 +969,59 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
969
969
970
970
} ) ;
971
971
} ;
972
-
972
+
973
+ // ## Add attachment to issue ##
974
+ // ### Takes ###
975
+ //
976
+ // * issueId: the Id of the issue to delete
977
+ // * path: local path to the attachment
978
+ // * callback: for when it's done
979
+ //
980
+ // ### Returns ###
981
+ // * error string
982
+ // * success string
983
+ //
984
+ // [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#idp2051136)
985
+ this . attachToIssue = function ( issueNum , path , callback ) {
986
+ var self = this ;
987
+ var options = {
988
+ rejectUnauthorized : this . strictSSL ,
989
+ uri : this . makeUri ( '/issue/' + issueNum + '/attachments' ) ,
990
+ method : 'POST' ,
991
+ followAllRedirects : true ,
992
+ json : true ,
993
+ headers : {
994
+ 'x-atlassian-token' : 'nocheck'
995
+ }
996
+ } ;
997
+
998
+ var form = new FormData ( ) ;
999
+ form . append ( 'file' , fs . createReadStream ( path ) ) ;
1000
+
1001
+ form . getLength ( function ( err , length ) {
1002
+
1003
+ var form_request = self . request ( options , function ( error , response ) {
1004
+ if ( error ) {
1005
+ callback ( error , null ) ;
1006
+ return ;
1007
+ }
1008
+
1009
+ if ( response . statusCode === 200 ) {
1010
+ callback ( null , "Success" ) ;
1011
+ return ;
1012
+ }
1013
+
1014
+ callback ( response . statusCode + ': Error while uploading' ) ;
1015
+
1016
+ } ) ;
1017
+
1018
+ form_request . setHeader ( 'Content-Length' , length ) ;
1019
+ form = form_request . form ( ) ;
1020
+ form . append ( 'file' , fs . createReadStream ( path ) ) ;
1021
+ } ) ;
1022
+
1023
+ } ;
1024
+
973
1025
// ## List all Viewable Projects ##
974
1026
// ### Takes ###
975
1027
//
0 commit comments