floralvikings / jira-connector

NodeJS Wrapper for the Jira REST API
http://floralvikings.github.io/jira-connector/
MIT License
373 stars 180 forks source link

Add Multiple attachment(jpg/png/txt) in issue produce file with no extension on jira #108

Closed abhishekvishwakarmagate6 closed 5 years ago

abhishekvishwakarmagate6 commented 6 years ago

Hello, I have tried to add multiple file attachment with a issue.I have used tmp path to upload the files in node js .All the file got uploaded successfully,but the issue i find is that the file name is got uploaded without any extension on jira (For ex - upload_2160b1ed5a7ebeaef62ace3790e58426).Hence the images are not visible on jira ,when i view any issue which have attachment include images format.I have also searched for the solution which i resolved it,Please update it on ur side -

this.addAttachment = function (opts, callback) {
        if (!opts.filename) {
            throw new Error(errorStrings.NO_FILENAME_ERROR);
        }
        var options = this.buildRequestOptions(opts, '/attachments', 'POST');
        delete options.body;
        if (opts.filename.constructor !== Array) opts.filename = [opts.filename];
        var attachments = opts.filename.map (function (filename) {
             return {
                      value: fs.createReadStream(filename),
                      options: {
                              filename: '<filename>',
                              contentType: '<fileType>'
                      }
              }
        });
        options.formData = {file: attachments};
        options.headers = {
            "X-Atlassian-Token": "nocheck",
            'charset': 'UTF-8'
        };

        return this.jiraClient.makeRequest(options, callback);
    };

In this code - i have added "value" with "options" under filename map section ,you need to provide a proper file name with extension with its content type.Then after it will display the image file on jira successfully.

floralvikings commented 5 years ago

This repository is only very lightly maintained; you are welcome to submit a pull request if there is behavior you'd like to add, I do occasionally check the PR list and merge code that is within the scope of this tool and doesn't include breaking changes.

If you have found a bug please indicate the desired behavior and provide a minimal example demonstrating the incorrect behavior; I do try to fix bugs as they come up but I have very little time to devote to this repository anymore, so I can't make any guarantees.

If you have a feature you'd like to request, please indicate the desired behavior. I will almost certainly never have the time to implement it myself but this repository does see occasional PR activity so it may be added by a generous contributor. You are, of course, welcome to submit a pull request yourself implementing the desired behavior.

MrRefactoring commented 5 years ago

Solved in 2.12.0 version