HTML with Additional Pickers
<form id="cadUploadForm">
<input type="file" id="cadFilePicker" accept=".cad,.zip" />
<br/>
<label for="dimensionType">Dimension Type:</label>
<select id="dimensionType">
<option value="3D">3D</option>
<option value="2D">2D</option>
</select>
<br/>
<label for="outputFileType">Output File Type:</label>
<select id="outputFileType">
<option value="GLB">GLB</option>
<!-- Add other file types as needed -->
</select>
<br/>
<label for="takeScreenshot">Take Screenshot:</label>
<input type="checkbox" id="takeScreenshot">
<br/>
<label for="assemblyMode">Assembly Mode:</label>
<select id="assemblyMode">
<option value="full">Full</option>
<option value="subassembliesOnly">Subassemblies Only</option>
<option value="unimodel">UniModel</option>
</select>
<br/>
<button type="submit">Upload</button>
</form>
Updated JavaScript with Fetch Request
document.getElementById('cadUploadForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevents the form from submitting the traditional way
let fileInput = document.getElementById('cadFilePicker');
let file = fileInput.files[0];
if (!file) {
alert('Please select a CAD file.');
return;
}
// Construct FormData
let formData = new FormData();
formData.append('CADFile', file);
formData.append('DimensionType', document.getElementById('dimensionType').value);
formData.append('OutputFileType', document.getElementById('outputFileType').value);
formData.append('TakeScreenshot', document.getElementById('takeScreenshot').checked);
formData.append('AssemblyMode', document.getElementById('assemblyMode').value);
// Fetch request
fetch('https://convert.renderdraw.us/CAD/2.0/', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Success:', data);
// Handle the response data
})
.catch(error => {
console.error('Error:', error);
});
});