Hey Community! I’m trying to create a simple text file as a blob in forge Custom UI and attach it to an existing Jira issue.
My code in the react component:
async function AddAttachmentToIssue(){
const form = new FormData();
const blob = new Blob(['HelloWorld!'], {type : 'text/plain'})
form.append('file', blob, 'file.txt')
const response = await invoke('addAttachmentToIssue', form);
console.log(`AddAttachmentToIssue:`, response);
}
And code in the resolver function definitions file:
We are aware of some issues regarding attachments and the Forge lambda/resolver.
For uploading an attachment from the client-side of a Custom UI app, it may be easiest to use requestJira from the Custom UI bridge. This will make the request directly to the product API on the client-side, rather than via the resolver/lambda.
Hello @kchan , solution with Request.text() works but only for text files. For binary images file uploaded too but it have wrong format. There is code sample for PNG image:
///////////////////////////////////////////
// Create Canvas for draw and upload as image
var canvas = document.createElement('canvas');
canvas.id = "canvasImage";
canvas.width = 100;
canvas.height = 100;
canvas.style.zIndex = 8;
canvas.style.position = "absolute";
canvas.style.top = 0;
canvas.style.left = 0;
document.body.appendChild(canvas)
var ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(0, 255, 0, 1.0)";
ctx.fillRect(0, 0, 100, 100);
//////////////
// Convert canvas to Blob and upload it
canvas.toBlob((blob) => {
const form = new FormData();
form.append("file", blob, "file.png");
const req = new Request("", {
body: form,
method: "POST",
});
req.text().then((body) => {
console.log(body);
requestJira("/rest/api/3/issue/VIS-10/attachments", {
method: "POST",
body,
headers: {
'Content-Type': req.headers.get('content-type'),
Accept: "application/json",
"X-Atlassian-Token": "no-check",
},
})
.then((response) => {
console.log(`Response:`, response);
});
});
});
///////////////////////////////////////////
@Yaroslav@naseriimahmoud, unfortunately I’m not aware of a solution here. We will soon look into a fix for this but it doesn’t seem to be trivial (or close to trivial) so may take some time.
Thank you @kchan. I personally will look forward to attaching the video file created using bloob. I would greatly appreciate it if you could test this case while working on it.