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

Search Atlassian Confluence Page hierarchy for all task lists
Is it possible to factory-reset an HipChat server?
Hipchat-Confluence Integration on something other than a space
Viewing permissions in Atlassian Stash
Why https://media-api.atlassian.io returns 503?
How's atlassian working with register company vs unregister company on sub-domain
Couldn’t load the class ‘com.atlassian.confluence.themes.BasicTheme
What is the practical difference between atlas-run and atlas-run-standalone in the Atlassian SDK?
Commit Not Found on Bitbucket on PreReceiveRepositoryHook
Making text bold based on page tree depth in Confluence
Sql query to get all pages and their associated links for all confluence spaces
Atlassian Crowd Custom Connector Issue with AddUser - looking for Example Code and Documentation
WARNs in Confluence 6.0.1 after upgrade
compact code block in confluence wiki
Atlassian Confluence: Rest Api Create attachments Error 500 and Permission denied
Atlassian Git API Diff Commits using Git notation

Categories

HOME
cygwin
azure-stream-analytics
google-spreadsheet
obfuscation
r-googlesheets
spring-data-mongodb
jquery-ui
android-json
data-visualization
missing-data
vimdiff
openpyxl
datastage
angular-dart
code-generation
symbol
azure-iot-hub
esoteric-languages
package.json
dynamic-sql
apache2.4
displaytag
resourcebundle
mount
froala
jasmine-node
asymptotic-complexity
delimiter
bringtofront
anki
catch-unit-test
papaparse
browser-extension
docfx
alphabetical
google-knowledge-graph
xdocreport
dcmtk
softmax
sharp-snmp
ssrs-2014
tcc
drupal-theming
vaadin-charts
facebook-social-plugins
httrack
ntvs
remedy
payara-micro
amq
sundials
seq
gameplay-kit
branch-prediction
cvxpy
vcloud-director-rest-api
cronexpression
atlas
actor-platform
signalr.client
x-tag
clipboard.js
omniauth-facebook
lua-telegram-bot
angular-ui-typeahead
beanstalk
linklabel
jdi
morton-number
jdk1.7
rdflib
airbrake
graphics2d
keyup
dnssec
google-refine
diff3
mmwormhole
linkedin-jsapi
mobility
cuba
mutual-authentication
radiant
git-repo
script#
pclzip
insert-id
windows-98
joomla3.1
paginator
lambdaj
appjs
user-tracking
u2netdk
google-ajax-api
drawtobitmap
cac
office-2007
scrollbars
lxr
localizable.strings
sqlobject

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