\n
File Upload Example
\n\n \n \n \n\n <-help;script>\n // Replace this with the presigned URL generated in Step 1.\n const signedUrl = ""; \n\n\n document.getElementById('uploadButton').addEventListener('click', async () => {\n const fileInput = document.getElementById('fileInput');\n const file = fileInput.files[0];\n\n if (!file) {\n alert('Please select a file to upload.');\n return;\n }\n\n try {\n await upload(file, signedUrl);\n alert('File uploaded successfully!');\n } catch (error) {\n console.error('Error during upload:', error);\n alert('Upload failed: ' + error.message);\n }\n });\n\n /**\n * Upload the file to OSS.\n * @param {File} file - The file to upload.\n * @param {string} presignedUrl - The presigned URL.\n */\n const upload = async (file, presignedUrl) => {\n const response = await fetch(presignedUrl, {\n method: 'PUT',\n body: file, // Upload the entire file directly.\n });\n\n if (!response.ok) {\n throw new Error(`Upload failed, status: ${response.status}`);\n }\n\n console.log('File uploaded successfully');\n };\n <-help;/script>-help;\n