Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Attachment upload from Instance A to Instance B

Kaspars Naumovs
January 18, 2021

Hi,

I have two JIRA instances located in two different data-centers.

I am trying to develop a functionality via workflow post function that would copy attachments from issue in Instance A to an issue in Instance B.

I have scriptrunner in both of my JIRA instances.

For now I am just trying to get one attachment via API and upload it to an issue in the same instance via API.

The code below creates the attachment (I am running it from ScriptRunner script console) - however I am only able to upload text attachments.

def connection = new URL("https://xxxx/secure/attachment/10108/test.txt").openConnection() as HttpURLConnection
connection.setRequestMethod( "GET" )
connection.setRequestProperty( "Authorization", "Basic xxxxxxxxxxx" )
connection.doOutput = true
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.connect()
def image = connection.inputStream.text

def body = "---\r\nContent-Disposition: form-data; name=\"file\"; filename=\"text.txt\"\r\nContent-Type: text/plain\r\n\r\n $image \r\n---"

def upConnection = new URL("https://xxxxxxxxxxxxx/rest/api/latest/issue/xxxxxxxxxx/attachments").openConnection() as HttpURLConnection
upConnection.setRequestMethod( "POST" )
upConnection.setRequestProperty( "Authorization", "Basic xxxxxxxxx" )
upConnection.setRequestProperty( "X-Atlassian-Token", "nocheck" )
upConnection.setRequestProperty( "Content-Type", "multipart/form-data; boundary=-")
upConnection.doOutput = true
upConnection.getOutputStream().write(body.getBytes())
upConnection.connect()
def upCode = upConnection.getResponseCode();
def upResult = upConnection.inputStream

upResult.text

 

1 answer

1 accepted

1 vote
Answer accepted
Nick
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 8, 2012

Hi Martha,

Xcode adds the DEBUG flag by default to your project settings for the Debug build configuration.

This is not added for the Release configuration. This means that when your app is build using the Release configuration, JMC log statements wont appear when run on the device.

Whilst this may not be the case for all projects, the reason we chose this approach was that we figured it is actually better to have no logging, than to have logging. For example, the api-key could potentially get leaked to the user if logs are accidently turned on and a URL is logged.

Cheers,

Nick

Martha Castillo
January 8, 2012

Hi, Nick.

Thanks for your reply.


I found that my project had the DEBUG flag lost in the "twilight zone", because it was created with Xcode 3.2.x some time ago; the default compiler for that Xcode versions used to be GCC, and DEBUG is not a defined macro in GCC.
Instead, the default compiler for Xcode 4.x is LLVM, and DEBUG is a defined macro in LLVM; so when you create a new project with Xcode 4.x, it adds the DEBUG flag by default to the project settings for the Debug build configuration, as you said.


Cheers,

MC

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events