Hello
I am trying to send a file as attachment using Jira Rest API, I am doing this from inside the electron and I am doing the following:
I am setting the request (Post):
var XMLHttpRequest = require('xhr2');
var xhr = new XMLHttpRequest();
xhr.open("POST","myInstance/rest/api/2/issue/ticketid?attachements",true);
xhr.setRequestHeader("Authorization","Basic"+Buffer.from("myUserName"+":"+"myToken").toStrin("base64"));
let file = "file=@'D:\\Testing Jira API\\testing.txt";
xhr.send(file);
xhr.onload = function (){ console.log("the statues is ", status);
let file = new File(["hello", new TextEncoder().encode("world.txt")],"hello.txt);
//using web-file-polyfill
Welcome to the Community!!
Why Complexity? Just Uploading the file directly will do the work
Try this
curl --location \
--request POST 'https://your-domain.atlassian.net/rest/api/3/issue/TEST-123/attachments' \
-u 'email@example.com:<api_token>' \
-H 'X-Atlassian-Token: no-check' \
--form 'file=@"myfile.txt"'
Thanks
Thanx @Pramodh M @for your response .. but my task is requiring to do that using electron, or you mean by calling curl commands (for instance from the node.js itself in the electron using node-libcurl)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When Using Libraries, we should check once whether it's supported! ( XMLHttpRequest - not sure about this one here)
using Electron is fine, but may I know the method you are following here?
If you see the documentation, there are examples for various methods
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pramodh M
I followed the example here
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post
worked for me
thanx for you suggestion
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your API endpoint is incorrect
Instead of
http://myinstance/rest/api/2/issue/ticketid?attachements
you need to use
http://myinstance/rest/api/2/issue/ticketid/attachments
Alex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, but I still have a problem if I am trying to use xmlHttpRequest using xhr2
var XMLHttpRequest = require('xhr2');
var xhr = new XMLHttpRequest();
const fs = require('fs);
const filePath = 'test2.txt';
const state = fs.stateSync(filePath);
const fileSizeInBytes = state.size;
const fileStream = fs.createReadStream(filePath);
form.append('file', fileStream, {knownLength: fileSizeInBytes});
xhr.opern("POST" , "httes://myinstance.atlassian.net/rest/api/2/issue/ticketid/attachements", true);
xhr.setRequestHeader("Authorization", ...);
xhr.setRequestHeader("Accept","application/json");
xhr.setRequestHeader("X-Atlassian-Token", "no-check");
xhr.send(form)
and I am getting unsupported send() data [object FormData]
and I think it is something regarding xhr2 more that jira API itself, so I followed their way
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have a typo in
httes://myinstance.atlassian.net/rest/api/2/issue/ticketid/attachements
And instead of "ticketid" you need to put an ACTUAL Jira issue key
As for "unsupported send() data [object FormData]" - cannot tell as I have no idea what "xhr2" is... if it's an npm package https://www.npmjs.com/package/xhr2 then probably the code makes sense
Anyway the error is on your side (in a script) - not on Jira
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
for typos and actual jira issue key they are correct in my real code ..I just retyped it here instead of copying it
the problem is in xhr2 itself I guess
send()
accepts the following data types: String, ArrayBufferView, ArrayBuffer (deprecated in the standard)
The following standard features are not implemented.
file://
URIsdata:
URIsThanx for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alex Medved _ConfiForms_
Yes I know the problem was not in jira ..that is why I accepted the first answer the problem in my script is that I am using xhr2 with formData
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.