Hi everibody,
We have a big issue. We are trying to migrate some attachments from an external system to Asset, but we don't find any API to upload a binary. Do you have any suggestions? I'm really in trouble :sob:
To add more to @Christos Markoulatos
Go through this guide that Thomas gave. It should work for you. Let me know the results!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nikola Perisic and Hi @Christos Markoulatos ,
Thank you for sharing. We had already consulted your solution, and at the moment, we are using the approach you suggested. The problem is that in the second call, we cannot understand why the token that is generated seems to last only 60 minutes.
Firstly, we don't understand who generates this token, and secondly, how to increase its duration. To give you an idea of the scale, we are migrating attachments from an external CMDB to assets, and we are talking about hundreds of thousands of files of different sizes. It is unthinkable to have to change tokens every 60 minutes.
Kind Regards
Davide
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can create a script to retrieve attachments and send them to Assets.
In this script, you could refresh the JWT token after a certain number of attachments have been sent. For example, you can renew it once every 10,000 attachments inside the loop.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
its not possible, only from the UI
Note that attachments can't currently be added via the REST API or CSV.
Unless something has changed recently and they haven't document it yet.
not much help, sorry!
Solved: How do I add a file to the attachments section of ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Adding to he another comments:
If you need upload the attachments one time, I have a solution for you.
That way will not work if you need synchronise two systems, but it works on demand.
Analyzing the interface upload button to attach files on Assets, using the dev tools, we can find 3 sequence commands:
Is it possible create a script reading a csv file with object id and file path informations to upload many files in one execution.
In bellow the simple bash script that I created when I was testing it:
#!/usr/bin/env bash
set -euo pipefail
# 🔧 Configurations
WORKSPACE="afd1a" # workspaceId
OBJECT_ID="16" #objectId
JIRA_URL="https://yoursite.atlassian.net"
CRED_URL="${JIRA_URL}/gateway/api/jsm/assets/workspace/${WORKSPACE}/v1/attachments/object/${OBJECT_ID}/credentials"
FILENAME="anexo.png" # filename
LOCAL_FILE="anexo.png" # local filepath
# 1️⃣ get temporary credentials
echo "[INFO] Getting temporary credentials..."
RESPONSE=$(curl -s "$CRED_URL" \
-H "accept: application/json" \
-H "content-type: application/json" \
-b 'ajs_anonymous_id=%22d47c5516-1047-48d7...') # put the cookie found via devtools here
# Extrair dados
CLIENT_ID=$(echo "$RESPONSE" | jq -r '.clientId')
TOKEN=$(echo "$RESPONSE" | jq -r '.mediaJwtToken')
MEDIA_BASE=$(echo "$RESPONSE" | jq -r '.mediaBaseUrl')
echo "[INFO] Client ID: $CLIENT_ID"
echo "[INFO] Token retrieved."
# 2️⃣ Upload file to Media Service
echo "[INFO] Uploading $LOCAL_FILE to Jira Media Service..."
UPLOAD_URL="${MEDIA_BASE}/file/binary?name=${FILENAME}"
UPLOAD_RESPONSE=$(curl -s -X POST "$UPLOAD_URL" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: image/png" \
-H "x-client-id: $CLIENT_ID" \
--data-binary "@${LOCAL_FILE}")
echo "$UPLOAD_RESPONSE" | jq .
MEDIA_ID=$(echo "$UPLOAD_RESPONSE" | jq -r '.data.id')
if [[ "$MEDIA_ID" == "null" ]]; then
echo "[ERROR] Unable to retrieve mediaId from upload!"
exit 1
fi
echo "[INFO] Upload completed, mediaId: $MEDIA_ID"
# 3️⃣ Associate file to Asset object
echo "[INFO] Associating file to object $OBJECT_ID in Jira Assets..."
ATTACH_URL="${JIRA_URL}/gateway/api/jsm/assets/workspace/${WORKSPACE}/v1/attachments/object/${OBJECT_ID}"
SIZE=$(stat -f%z "$LOCAL_FILE" 2>/dev/null || stat -c%s "$LOCAL_FILE")
# put the cookie found via devtools here
curl -s -X POST "$ATTACH_URL" \
-H "accept: application/json" \
-H "content-type: application/json" \
-b 'ajs_anonymous_id=%22d47c5516-1047-48d7...' \
--data-raw "{
\"attachments\": [
{
\"contentType\": \"image/png\",
\"filename\": \"${FILENAME}\",
\"mediaId\": \"${MEDIA_ID}\",
\"size\": ${SIZE},
\"comment\": \"\"
}
]
}" | jq .
echo "[INFO] Attachment successfully associated!"
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.