0

I could successfully compile design automation web application with input file, as RVT and Json attached. But I need to pass only a Json file, as input for workItem. in ForgeDesignAutomation.js, I wrote it as below. But looks like inputfile need to be stringified . Please help me to correct the syntax below.

here 'inputFile' is a Json file, I am not uploading any rvt file, as my addin takes only a json file as input, which is array of strings and return a rfa file as output.

How to stringify 'inputFile', when it is just a .json file ?

function startWorkitem()
{
var inputFileField = document.getElementById('inputFile');
if (inputFileField.files.length === 0) { alert('Please select an input file'); return; }
if ($('#activity').val() === null) { alert('Please select an activity'); return };
var file = inputFileField.files[0];

let activityId = $('#activity').val();
if (activityId == null)
{
    alert('Please select an activity'); return
};

if (activityId.toLowerCase() === "myfirst_da4ractivity+dev")
   {
    startConnection(function () {
        var formData = new FormData();
        formData.append('inputFile', file);
       //file is not uploading-------I think I could not pass the Json file. 
       //I need to pass connection ID here too. 
        writeLog('Uploading input file...');
    $.ajax({
            url: 'api/forge/designautomation/workitems',
            dataType: 'json',
            data: formData,
            processData: false,
            contentType: false,
            type: 'POST',
        success: function (res)
            {
                writeLog('Workitem started: ' + res.workItemId);
            }
        });
    });
}

}

nayra n
  • 29
  • 7
  • Unfortunately there is not enough info in your original post to answer this question. If you are modifying an existing code sample and your modifications do not work, mentioning original code and your changes may help us answer. As to being able to send an input json to a design automation workitem, please refer the SketchIt sample: Here is the server side code: https://github.com/Autodesk-Forge/forge-sketchit-revit/blob/c3b6c41e4e5d2d419b87d94b6c817c535ba220f1/server/src/main.js#L118-L120 https://github.com/Autodesk-Forge/forge-sketchit-revit – Rahul Bhobe Jun 08 '20 at 05:47
  • Yes, true, I did not write the the question properly. Thanks for the reply. I am working with dotnet core. Controller in server side and JavaScript/ajax in client side. In web form I am only passing a Json file. I am following two sample codes, both uses revit files, none of them uses just Json file as input, as formdata. I do plugin developement extensively, but this is the first time front end/back end communication. So doing some stupid mistakes. Will overcome soon. Will be back with a better question :) Trying to understand the sample codes, and what is going on :) – nayra n Jun 08 '20 at 14:44
  • 1
    Hi @nayran, Have alook at https://stackoverflow.com/questions/62286622/json-files-as-parameter-input-using-forge-design-automation I think you question is same and Charles Dodson answered it very well there. – denis-grigor Jun 10 '20 at 16:18

1 Answers1

1

From your question, you have a client, that submits to your server, which then submits to Forge.

That way, how you submit to api/forge/designautomation/workitems endpoint varies on how it's expecting the data. As you have a .json file, you don't need to stringfy is, it's passed as a file. If you decide to send it as data, then stringfy and adjust to data: { your JSON data here },

Assuming the file came from your client to your server, you can then submit that JSON file to Forge as an input for your Workitem.

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • Thanks for the reply ! within last few days I understood that. But now a new problem, I have one rfa file and one big Json file to upload as work item. Do I need to upload the json content to a cloud storage and pass the signed url to the file as input argument URL ? Is there any example showing multiple input files ? I do not see any syntax error now. Json file is not bigger than 4 kb now, but it will be big later. Everything looks ok. Code is stack at :WorkItemStatus workItemStatus = await _designAutomation.CreateWorkItemAsync(workItemSpec); – nayra n Jun 11 '20 at 13:06
  • great, glad it's working. If this question is done, please "accept as answer". I saw you already posted the other question, a colleague is looking into it. – Augusto Goncalves Jun 11 '20 at 17:29