I’m capturing audio via the web using the JavaScript MediaRecorder API. I then send this media to a Go server, which then sends it to WhatsApp.
Form in Go:
vFile,_= os.Open(this.URL)
vBuffer := new(bytes.Buffer)
vMultipart := multipart.NewWriter(vBuffer)
vMIMEHeader := make(textproto.MIMEHeader)
vMIMEHeader.Set("Content-Disposition","form-data; name="file"; filename="" + this.GetFileName() + """)
vMIMEHeader.Set("Content-Type",vMIMEType)
vIOWriter, _ := vMultipart.CreatePart(vMIMEHeader)
io.Copy(vIOWriter,vFile)
vIOWriter, _ = vMultipart.CreateFormField("type")
vIOWriter.Write([]byte(vMIMEType))
vIOWriter, _ = vMultipart.CreateFormField("messaging_product")
vIOWriter.Write([]byte("whatsapp"))
vMultipart.Close()
this.GetFileName() = “audio.mp3”
vMIMEType = “audio/mpeg”
When uploading the file, WhatsApp successfully receives it and creates an id for it.
However, when sending an audio message referencing the created id, I receive the following return:
“errors”:[{“code”:131053,”title”:”Media upload error”,”message”:”Media upload error”,”error_data”:{“details”:”Audio file uploaded with mimetype as audio/mpeg, however on processing it is of type application/octet-stream. Please choose a different file.”}}]
Thanks for all the help.
Some points:
A) I searched the documentation and the media type is allowed;
B) I sent the file in mp3 format stating the MIME type as audio/mpeg;
Documentation:
https://developers.facebook.com/docs/whatsapp/cloud-api/support/error-codes
https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types