I need to download all attachments for specified issue in jira.
This code downloads file, but it's corrupted.
Can anyone help, how to correctly work with attachments?
import com.atlassian.jira.rest.client.api.JiraRestClient
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory
import java.io.FileOutputStream
import java.net.URI
import java.nio.channels.Channels
import java.io.BufferedInputStream
import java.io.IOException
import java.net.URL
@Throws(IOException::class)
private fun downloadUsingStream(urlStr: String, file: String) {
val url = URL(urlStr)
val bis = BufferedInputStream(url.openStream())
val fis = FileOutputStream(file)
val buffer = ByteArray(1024)
var count = 0
while (bis.read(buffer, 0, 1024) != -1) {
fis.write(buffer, 0, buffer.size)
}
fis.close()
bis.close()
}
fun main(args: Array<String>) {
val jiraURI = URI("http://jira/")
val factory = AsynchronousJiraRestClientFactory()
val client: JiraRestClient = factory.createWithBasicHttpAuthentication(jiraURI,"login","password")
val issueClient = client.issueClient
client.use {
issueClient.getIssue("attachment").claim().attachments.forEach {attachment->
val website = attachment.contentUri.toURL()
downloadUsingStream(website.toString(),attachment.filename)
}
}
}
Thank god, finally I find a solution in Java.
JiraRestClient client = factory.createWithBasicHttpAuthentication(jiraURI,"login","password")
//cast JiraRestClient to AsynchronousIssueRestClient
AsynchronousIssueRestClient issueClient=(AsynchronousIssueRestClient) client.getIssueClient();
URL url=new URL("your attachment url");
Promise<InputStream> attachment=asynchronousIssueRestClient.getAttachment(url);
InputStream inputStream=attachment.get();
//then you can do whatever you want with that inputStream
@蒋雨辰Can you please suggest anything in php for this issue? Or just basic steps with jira url.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.