Call attachPhysicalFile in javascript from an itemtype

Hi,

I have an ItemType "COCO_STUDY" with a relation "COCO_STUDY_FILE" pointing to a "File".

On the form of this ItemType, I have a html/javascript widget to import a CSV file.
The selection of the file is done with <input type="file">.

I would like to implement an option (here: "Add imported file in documents"), to copy the selected and imported document into ARAS (as a File) and pointed by the current "COCO_STUDY" through a "COCO_STUDY_FILE".

I understood that I need to use attachPhysicalFile but how ?

If I well understood, for security reason, the browser doesn't fullpath of the selected file.
So, I don't know how to pass it to attachPhysicalFile.

I tried to hardcode the filename for a test but it doesn't work.

I did this javascript code

if(add_imported_file) {
// Add imported file in ARAS
let inn = top.aras.newIOMInnovator();
let link_study_file = inn.newItem("COCO_STUDY_FILE", "add");

let fileAras = inn.newItem("File", "add");
fileAras.setProperty("filename",fileInput.files[0].name);
fileAras.setProperty("comments", "Imported");
//URL.createObjectURL(fileInput.files[0])
fileAras.attachPhysicalFile("C:\\Users\\to81591\\Documents\\Development\\cawb\\sample_csv_files\\CAD2BOM v0.1_UPDATED.csv")

link_study_file.setRelatedItem(fileAras);
document.thisItem.addRelationship(link_study_file);
}

So, in javascript, how to create a "File" from a file selected from an <input type="file"> ?

Regards.

Parents Reply Children
No Data