You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Recordmp3js保存MP3到服务器出现损坏的技术求助

Troubleshooting Corrupted MP3 Uploads with Recordmp3js

Hey there, sorry to hear you're stuck with this frustrating corrupted MP3 issue—let's break down the most likely culprits and actionable fixes to get your uploads working properly:

1. Validate Frontend Upload Data Integrity

First, confirm the data you're sending from the browser to upload.php matches the working MP3 you can play locally:

  • Double-check you're properly packaging the recorded audio blob using FormData (the standard, reliable way to upload files via AJAX). If you're manually converting the blob to a string or using wonky encoding (like Base64 without proper server-side decoding), that's a top cause of corrupted files.
  • Add a quick sanity check in your frontend code: log the size of the generated blob (console.log(recordedBlob.size)) and compare it to the file size on your server. If they don't match, your data is being truncated or modified mid-transit.

2. Audit Your upload.php Server Logic

Most corrupted upload issues trace back to server-side handling—here's what to check:

  • Verify PHP upload limits: Open your php.ini file and ensure upload_max_filesize and post_max_size are set to values larger than your MP3 files. If the file exceeds these limits, PHP will silently truncate it, resulting in that short pink noise you're hearing.
  • Validate file handling code: Make sure you're using move_uploaded_file() correctly, and that the target directory has proper write permissions. Avoid unnecessary processing (like string manipulation) on the uploaded file data—if you're reading and re-saving the file, use binary modes (rb/wb) in fopen instead of text modes, which can mangle audio data.
  • Test raw POST data: Temporarily modify upload.php to save the raw input directly, bypassing $_FILES processing:
    file_put_contents('test_upload.mp3', file_get_contents('php://input'));
    
    If this test file plays correctly, the issue is with your $_FILES logic. If it's still corrupted, the problem lies in how your frontend is sending the data.

3. Check for Encoding/Transmission Mistakes

  • If you're using a custom AJAX request (not relying on FormData), ensure you're setting the right headers and response type. For binary uploads, avoid manually setting Content-Type unless you're using multipart/form-data, and don't set xhr.responseType to text—this will mangle binary audio data.
  • Skip converting the audio blob to Base64 unless you explicitly decode it on the server. Base64 adds overhead and introduces extra points where encoding can go wrong.

4. Cross-Check Recorded Blob vs. Uploaded File

Create a temporary download link in your frontend to save the locally generated MP3 to your computer. Then compare its MD5 hash to the file on your server. If the hashes don't match, your data is being altered during upload or saving. If they do match, the issue might be with how your server serves the file (incorrect MIME type, for example)—but since you said the generated link plays fine, this is less likely.

If you can share snippets of your frontend upload code and upload.php, we can narrow this down even further!

内容的提问来源于stack exchange,提问作者WannaBaCODER

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:12:51