Forums

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

get path attachments groovy

alex October 18, 2018

Could you please give me a help?
 I'm writing the script which copy an attachment from space to space. But I can't get a path for attachment.


 def filePath = null
RequestFilePart requestFilePart = new RequestFilePart("application/octet-stream", attach.first().title.toString(), filePath, "file")
List<RequestFilePart> fileParts = new ArrayList<RequestFilePart>()
fileParts.add(requestFilePart)

authenticatedRequestFactory
.createRequest(Request.MethodType.POST, "rest/api/content/" + conf.id + "/child/attachment")
.addHeader("X-Atlassian-Token", "nocheck")
.setFiles(fileParts)
.execute(new ResponseHandler<Response>() {
@Override
void handle(Response response) throws ResponseException {
if(response.statusCode != HttpURLConnection.HTTP_OK) {
throw new Exception(response.getResponseBodyAsString())
} else {
def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
}
}
})

 

1 answer

0 votes
Maksim Smetannikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2018

Hi! You have an "attach" variable but no declaration of it.

If in the second line your code  declaration "attach" variable look like this:

def attach = page.getAttachments()

You can get the attachment path as follows:

attach.first().getDownloadPath().toString()
alex November 14, 2018

Hi.
I'm sorry, but you give me a web link to download, and I need a path where the attachment is hosted on the server

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events