I am deveoping a plugin in which I need toupload selected document to my plugin. I am able to upload all type of file except .ai file. When I try to upload .ai file Illustrator became Inactive and I have to quit and reopen it to use. Can anyone suggest what should I do to upload .ai file. Please refer my code for reference:-
function uploadAssets() {
var doc = app.activeDocument;
var placedItem = doc.selection[0];
if(placedItem === undefined){
return JSON.stringify({imageData : null , imagePath : "no item selected"})
} else {
var imageFile = new File(doc.fullName);
// selected path name
var selectedPath = imageFile.fsName
// Converting file to binary data
imageFile.open("r");
imageFile.encoding = "Binary";
var binaryData = imageFile.read();
imageFile.close();
return JSON.stringify({imageData : binaryData, imagePath : selectedPath})
}
}
and I am calling this function using evalScript
csInterface.evalScript(`uploadAssets()`, async (res) => {
const resData = JSON.parse(res)
if(resData.imageData !== null) {
// Image binary data
const binData = resData.imageData
//Image file path
const imgPath = resData.imagePath
const splitModifiedPath = imgPath.split('/');
// Name of the file
const fileName = splitModifiedPath[splitModifiedPath.length - 1];
const fileArray = fileName.split(".")
// file extension
const extension = fileArray[fileArray.length - 1]
const buffer = new ArrayBuffer(binData.length);
const view = new Uint8Array(buffer);
for (let n = 0; n < binData.length; n++) {
view[n] = binData.charCodeAt(n);
}
const type = `${extension}`;
const blob = new Blob([buffer], { type });
const fileUrl = new File([blob], fileName , {
lastModified: new Date().getTime(),
type,
});
setSelectedFrameName(fileUrl.name)
handleSelectedFrame(fileUrl)
} else {
setSelectedFrameName(resData.imagePath)
setNotSelected(true)
}
})
};
const handleTaskRadioFile = (e) => {
setCheckFile(e.target.checked);
setCheckFrame(false);
};
Please help me in this. I will be greatful for your help
Thanks