I am trying to use unirest to upload attachments in memory to avoid having to download and reupload the files. I have successfully made this happen, however, the content-type for the file is defaulting to application/octect-stream. I tried setting content-type in the header, but it doesn’t seem to like that. Does anyone have any insight on how to set the content-type for attachments using unirest?
Here is the code that is working with the wrong content-type:
function update_ticket(args){
var domain = kiskadomain;
var api_key = kiskaApiEncode;
var url = `${domain}/api/v2/tickets/${args.id}`;
unirest.put(url)
.headers({
Authorization : "Basic " + api_key
})
.attach('attachments[]', args.url)
.end(function (response) {
console.log(response.body);
if (response.status === 200) {
console.log({"body": response.body.ticket.attachments, "status": response.status});
}else{
console.log({"body": response.body, "status": response.status});
}
});
}
Here is the code that I have come up with thus far:
function update_ticket(args){
var domain = kiskadomain;
var api_key = kiskaApiEncode;
var url = `${domain}/api/v2/tickets/${args.id}`;
unirest.put(url)
.headers({
Authorization : "Basic " + api_key
})
.attach('attachments', args.arr)
.end(function (response) {
console.log(response.body);
if (response.status === 200) {
console.log({"body": response.body.ticket.attachments, "status": response.status});
}else{
console.log({"body": response.body, "status": response.status});
}
});
}
//args looks like
args = {
size: ticattach.attachments[0].size,
id: 183,
arr : [
ticattach.attachments[0].content_type,
ticattach.attachments[0].attachment_url
]
}
This is throwing an error of “Invalid value “undefined” for header “Content-Length””