Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

674
Views
Convierta el comando Curl con archivo WAV a solicitud web de Unity

Actualmente intento convertir un comando curl en una solicitud web de Unity

Comando de rizo:

 curl -H “x-app-key:APP_KEY_HERE“ / -F " file=@AudioFile.wav" / -F "user_token=USER_TOKEN_HERE" / -F "category=orange" / https://api.soapboxlabs.com/v1/speech/verification

Y el código que he intentado:

 private string url = "https://api.soapboxlabs.com/v1/speech/verification"; private string apiKey = "123456789"; void Start() { StartCoroutine(MakeSoapboxRequest()); } IEnumerator MakeSoapboxRequest() { List<IMultipartFormSection> form = new List<IMultipartFormSection> { new MultipartFormFileSection("file", "Assets\\Pilot1\\Audio\\soapbox_test.wav"), new MultipartFormDataSection("user_token", "aaa1234567"), new MultipartFormDataSection("category", "orange") }; UnityWebRequest request = UnityWebRequest.Post(url, form); request.SetRequestHeader("x-app-key", apiKey); yield return request.SendWebRequest(); if(request.isNetworkError || request.isHttpError) { Debug.LogError(request.error); } else { Debug.Log("No soapbox error"); Debug.Log(request.downloadHandler.text); } }

Sigue recibiendo un error HTTP/1.1.400 Solicitud incorrecta

Como puede ver, lo probé y comenté, también en el formulario WWW. ¿Tiene algo que ver conmigo enviando el archivo wav? Intenté enviarlo como bytes, pero quedé confundido. La API a la que lo envío solo acepta archivos wav. Devuelve un archivo JSON. Solo estoy usando downloadHandler.text como prueba.

Cualquier ayuda sería apreciada. No he usado CURL antes y es la primera vez que pruebo Unity Web Requests.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tenga en cuenta que la sobrecarga que está utilizando para el archivo es MultiPartFormFileSection(string data, string fileName)

y estados

data : Contenido del archivo a cargar.
fileName : Nombre del archivo subido por esta sección del formulario.

Entonces, lo que sucede aquí es: está intentando cargar "archivo" como el contenido del archivo en una sección de archivo anónimo .


Creo que debería obtener el byte[] y usar la sobrecarga MultipartFormFileSection(string name, byte[] data, string fileName, string contentType)

nombre Nombre de esta sección del formulario.
data Contenido sin procesar del archivo a cargar.
fileName Nombre del archivo subido por esta sección del formulario.
contentType El valor del encabezado Content-Type de esta sección.

me gusta

 // Of course you would probably do these async before running the routine to avoid freeze string yourFilePath; var bytes = File.ReadAllBytes(yourFilePath); new MultipartFormFileSection("file", bytes, "soapbox_test.wav", "application/octet-stream")

Finalmente nota:

Si bien una ruta como Assets\Pilot1\Audio\soapbox_test.wav podría o no funcionar en el editor de Unity, definitivamente fallará en una aplicación de compilación.

Debe poner su archivo en la carpeta StreamingAssets y acceder a él a través de

 var filePath = Path.Combine(Application.streamingAssetsPath, "fileName.extension");

o use PersistentDataPath (por supuesto, primero debe asegurarse de que su archivo esté almacenado allí)

 var filePath = Path.Combine(Application.persistentDataPath, "fileName.extension");
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!