Hey guys,
quick question because im stuck at a http multipart thing.
Im trying to post a mp3 to the groq api, which is just a small speach-to-text thing. Via postman it works perfectly fine.
If i do a simple multipart post request, like i do at other parts without a problem i get the following response:
{"error":{"message":"multipart: NextPart: EOF","type":"invalid_request_error"}}
Im thinking it has something todo with the mutlipart boundary.
Here is my code, maybe one of you has a idea:
function transcribeVoiceMail(){
var loFs = forms.email_inbox_list.foundset
if(!loFs || !loFs.getSelectedRecord()){
return
}
var lrRecord = loFs.getSelectedRecord()
if(utils.stringTrim(lrRecord.Betreff).toLowerCase().indexOf('voicemail') < 0){
plugins.webnotificationsToastr.info('Diese E-Mail enthält keine Voicemail!')
return
}
// --- check if there are any attachments ---
if(!databaseManager.hasRecords(lrRecord.mail_messages_to_mail_attachments)){
plugins.webnotificationsToastr.info('Diese E-Mail enthält keine Anhänge!')
return
}
var mp3Bytes = lrRecord.mail_messages_to_mail_attachments.getRecord(1).data
if (!mp3Bytes) {
plugins.dialogs.showErrorDialog("Fehler", "Keine MP3-Daten im Anhang gefunden.");
return;
}
var jsFile = plugins.file.createTempFile('voice','.mp3')
jsFile.setBytes(mp3Bytes)
var client = plugins.http.createNewHttpClient()
var request = client.createPostRequest('https://api.groq.com/openai/v1/audio/transcriptions')
request.forceMultipart(true)
request.addHeader('Authorization','Bearer gsk_XXX')
request.addHeader('Accept','application/json')
request.addFile('file','voicemail.mp3',jsFile,'audio/mpeg')
request.addParameter('model','whisper-large-v3')
request.addParameter('language','de')
var response = request.executeRequest()
if (response.getStatusCode() == 200) {
var result = JSON.parse(response.getResponseBody());
plugins.dialogs.showInfoDialog("Transkription", result['text']);
} else {
plugins.dialogs.showErrorDialog("Fehler", "Groq API antwortete mit Status: " + response.getStatusCode());
application.output(response.getResponseBody())
}
client.close()
}
Using Servoy Version: 2025.3.1.4043
Greetings and thanks