atlassian


Add attachment to Jira using REST API


I am trying to attach some file to Jira using rest API, if I do CURL, its working properly but from the code, no luck yet.
I have gone through some posts here but didn't really help. Here is my code.
uri = UriBuilder.fromPath(uri.toString().concat(issueKey).concat("/attachments")).build();
this.getPostRequest().setURI(uri);
try {
URL url = new URL(filePath);
File file = new File("target/tmp/"+fileName);
FileUtils.copyURLToFile(url,file);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
FormBodyPart bodyPart = FormBodyPartBuilder.create("file",new FileBody(file))
.setName("file")
.addField(MIME.CONTENT_DISPOSITION, "form-data; name=\"file\"; filename=\"\""+fileName+"")
.build();
builder.addPart(bodyPart);
this.getPostRequest().setHeader("X-Atlassian-Token","no-check");
this.getPostRequest().setHeader("Content-Type", "multipart/form-data;boundary="+ UUID.randomUUID());
this.getPostRequest().setEntity(builder.build());
HttpResponse response = this.restHttpClient.execute(this.getPostRequest());
return response;
} catch (IOException e) {
e.printStackTrace();
}
The response code is 200, but the data returned is [].
Can anyone help? Am I doing anything wrong?

Related Links

DITA to Confluence 5+
Get list of new wiki pages using Confluence API
Atlassian Plugin Descriptor XML Schema
Is there a way to use a plugin/macro in Confluence to display results on a page?
how to find out how many times blueprints in confluence has been used
Converting a RefApp REST plugin into a Confluence plugin
Show HTML artifacts in bamboo without downloading
Atlassian Bitbucket Server Precommit Issue getting files
Atlassian Stash popup on Pull Request
Failed to load resource:soy template {Not all code is in Soy V 2 syntax (found file simple.soy not in Soy V2 syntax). }
Integrate HipChat into Slack
Section in Atlassian products (refapp)
How to read a file contained as a hash in Atlassian Stash Repository Hook?
Is atlas-run the only way to see how the changes are reflected?
Restore Stash from backup
JIRA - Acknowledge Save Button When Configuring Slow-Loading Gadget

Categories

HOME
shell
asp.net-web-api
jwplayer
jsf-2.2
graphics
alarm
ms-access-2016
bitbucket-api
yandex
alsa
google-cloud-datalab
crystal-reports-2013
okhttp
gruntfile
azure-powershell
android-7.0-nougat
spring-async
backpack-for-laravel
inno-download-plugin
highstock
google-api-client
data.stackexchange.com
pylons
delimiter
handler
cppreference
gp
sqlpackage
testcomplete
gitlab-api
angularjs-material
login-script
twos-complement
android-maps-extensions
installshield-le
keras-layer
searchkit
openproject
playframework-2.1
zoomify
openalpr
odroid
gdata
diacritics
kill
ogc
skylink
berkeley-db-je
magento-2.0.7
rserve
flac
objectscript
renaming
sandcastle
omxplayer
xcode-server
dimension
hadoop-partitioning
phpwebsocket
maybe
dynamics-nav-2016
dynatree
morton-number
rpart
sony-lifelog-api
google-refine
document-repository
angular-gettext
pseudo-class
ss7
mintty
cancellation
tinyxml
extjs2
twitter-bootstrap-rails
android-audiorecord
syndicationfeed
eclipse-kepler
hibernate-entitymanager
script#
rolify
idn
joomla3.1
android-loadermanager
multiplexing
gobject-introspection
workflow-services
lr
instantiationexception
delimited-text
pos-for-.net
google-wave
httpcookie
pbcopy
mathematical-typesetting
image-capture
commercial-application

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App