49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
| <!DOCTYPE html>
 | |
| <html>
 | |
| <head>
 | |
|   <title>Audio Upload</title>
 | |
| </head>
 | |
| <body>
 | |
|   <h1>Upload Audio File</h1>
 | |
|   <form id="audio-upload-form" enctype="multipart/form-data">
 | |
|     <input type="file" name="audio" id="audio-file" accept="audio/*" required>
 | |
|     <br>
 | |
|     <button type="submit">Upload</button>
 | |
|   </form>
 | |
| 
 | |
|   <script>
 | |
|     const form = document.getElementById('audio-upload-form');
 | |
|     form.addEventListener('submit', async (event) => {
 | |
|       event.preventDefault();
 | |
|       
 | |
|       const fileInput = document.getElementById('audio-file');
 | |
|       const audioFile = fileInput.files[0];
 | |
|       
 | |
|       if (!audioFile) {
 | |
|         alert('Please select an audio file to upload.');
 | |
|         return;
 | |
|       }
 | |
| 
 | |
|       const formData = new FormData();
 | |
|       formData.append('audio', audioFile);
 | |
| 
 | |
|       try {
 | |
|         const response = await fetch('uploadaud', {
 | |
|           method: 'POST',
 | |
|           body: formData
 | |
|         });
 | |
| 
 | |
|         if (response.ok) {
 | |
|           const result = await response.json();
 | |
|           alert(`File uploaded successfully: ${result.filename}`);
 | |
|         } else {
 | |
|           const error = await response.json();
 | |
|           alert(`Error uploading file: ${error.message}`);
 | |
|         }
 | |
|       } catch (error) {
 | |
|         alert(`Error uploading file: ${error.message}`);
 | |
|       }
 | |
|     });
 | |
|   </script>
 | |
| </body>
 | |
| </html> |