I have a small issue with a button. When I click on it (see in image: 1), the CV is sent to the API and the result is generated and extracted on the other server. I added a "description" field so that the result can be displayed in it (see in image: 2) , but I've been trying to find the issue for a month now without success.
	
							
						
					PHP Code:
	
define('custom:views/button-handler', ['view', 'model'], function (Dep, Model) {
    return Dep.extend({
        setup: function () {
            this.listenTo(this.getView('testButton'), 'uploadPdf', this.actionUploadPdf);
        },
        actionUploadPdf: function (textZoneView) {
            let fileInput = document.createElement('input');
            fileInput.type = 'file';
            fileInput.accept = '.pdf';
            fileInput.onchange = (e) => {
                let file = e.target.files[0];
                this.sendFileToApi(file, textZoneView);
            };
            fileInput.click();
        },
        sendFileToApi: function (file) {
            let formData = new FormData();
            formData.append('file', file);
            // Change the URL to your API endpoint
            let apiUrl = 'http://xxxx:5000/summarize_resume';
            fetch(apiUrl, {
                method: 'POST',
                body: formData
            })
            .then(response => {
              // Log the raw response text
              console.log('API Response:', response); // Debugging line
              return response.json(); // Get the response as plain text
              })
            .then(data => {
                if (data.error) {
                  console.error('API error:', data.error);
                   }
                else {
                   // Insert the response text into the "description" field
                   let recordView = this.getView('recordView');
                   if (!recordView) {
                     console.log("'recordView' is not available");
                     return;
                     }
                let descriptionField = recordView.getField('description');
                descriptionField.setValue(data.summary);
                 }
                const blob = new Blob([data.summary], { type: 'text/plain' });
                // Create a temporary URL for the returned file
                const url = URL.createObjectURL(blob);
                
                 // Log the blob and URL to the console
                console.log('Blob:', blob);
                console.log('URL:', url);
                // Create an anchor element and set its attributes to trigger a download
                const a = document.createElement('a');
                a.href = url;
                a.download = 'summary.txt';
                // Trigger the download by clicking the anchor element
                a.click();
                // Release the temporary URL after the download
                setTimeout(() => {
                    URL.revokeObjectURL(url);
                }, 100);
            })
            .catch(error => {
                console.error('Error:', error);
            });
        }
    });
});
 

 Problem with a button
									
									
									Problem with a button
								
Comment