Adding attachment to Jira with Matlab RESTful API

I'm trying to add attachment to Jira issue from Matlab. The code below returns HTTP Status 200 OK, but the file is not added to the Jira issue. What is the reason for that?
import matlab.net.http.io.MultipartProvider
import matlab.net.http.io.FileProvider
import matlab.net.http.io.MultipartFormProvider
HeaderField = matlab.net.http.HeaderField('Authorization','Basic USERNAME:PASSWORD', 'Content-Type','multipart/form-data', 'X-Atlassian-Token','no-check');
fps = FileProvider("myfile.txt");
mp = MultipartProvider(fps);
formProvider = MultipartFormProvider("files",mp);
req = matlab.net.http.RequestMessage('post',HeaderField,formProvider)
req.send('https://XXX.atlassian.net/rest/api/2/issue/TEST-1/attachments')
I can add the attachment from windows command prompt using code (as instructed here: Atlassian document):
curl -D- -u USERNAME:PASSWORD -X POST -H "X-Atlassian-Token: no-check" -F "file=@myfile.txt" https://XXX.atlassian.net/rest/api/2/issue/TEST-1/attachments

2 件のコメント

Ray Oly
Ray Oly 2020 年 4 月 22 日
Hi Juho,
Have you found a solution to this issue?
Juho
Juho 2020 年 4 月 22 日
Hi Ray,
Unfortunately I haven't found solution for this.

サインインしてコメントする。

 採用された回答

Geoff Hayes
Geoff Hayes 2020 年 4 月 22 日

0 投票

Juho - since the CURL statement works, why not build that in MATLAB and use system to execute that statement?
userName = 'myUserName';
password = 'myPassword';
fileName = 'myfile.txt';
curlCommand = sprintf('curl -D- -u %s:%s -X POST -H "X-Atlassian-Token: no-check" -F "file=@%s" https://XXX.atlassian.net/rest/api/2/issue/TEST-1/attachments', ...
userName, password, fileName);
[status, cmdout] = system(curlCommand);

1 件のコメント

Juho
Juho 2020 年 4 月 23 日
Yes that would solve the problem. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCall Web Services from MATLAB Using HTTP についてさらに検索

製品

リリース

R2019b

質問済み:

2020 年 1 月 21 日

コメント済み:

2020 年 4 月 23 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by