📜  ZOHO API 将文件上传到当前形式 - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:35.844000             🧑  作者: Mango

代码示例1
//*******************************ALTERNATIVE FILE UPLOAD***********************************
//This FILE UPLOAD will upload a file into the current form, there is not a subform involved in this upload, it just directly goes to the form

btn_upload.addEventListener("click", () => {
    console.log("Uploading file...");

    //Setting up the config variables...
    var reportLinkName = "All_Visitors";//Name of the form where the file must be uploaded to
    var var_Subfield = "Sub_Upload_Field";//Name of the field where the file is to be stored
    var recordId = inp_ID_nr.value;//19 Digit ID for tje record where the file is to be stored


    //**************************setting up the config file...*************************8
    var config = {
        reportName: reportLinkName,//Name of the form where the file must be uploaded to
        id: recordId,//19 Digit ID for the record where the file is to be stored
        fieldName: var_Subfield,//Name of the field where the file is to be stored
    }

    if (upload_field.files.length > 0) {//checks to see if there is a file selected in the file upload field.
        config["file"] = upload_field.files[0];//if there is a file selected, that file is also added to the config
    }
    //****************************Config file setup completed************************* */


    console.log("Final config file: ");//logging the final config
    console.log(config);

    //ZOHO Magic...
    var getRecords = ZOHO.CREATOR.API.uploadFile(config);
    getRecords.then(function (jsonData) {//jsonData is the object received from Zoho
        console.log("Response received from Zoho: ");
        console.log(jsonData);//logging the response object to the console
        if (jsonData.code == 3000) {
            alert('The file has been uploaded successfully');
            console.log('The file has been uploaded successfully');
        }
    });
});