0

I need to upload audio file recorded in iOS device to server using PUT method in request. Now, I am confused that is it possible to upload audio file to server without multipart request in iOS Swift.

shim
  • 9,289
  • 12
  • 69
  • 108
Hunter
  • 31
  • 5
  • You can't upload audio file without multipart, you have to use multipart for upload audio file to server – Jignesh Mayani Jan 28 '21 at 10:51
  • https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2 ? Put should "update", not create ressources (https://reqbin.com/Article/HttpPut) which would be "POST". – Larme Jan 28 '21 at 10:54
  • i did try different technique but didn't work. Actually i am uploading audio on signed url (which is created on our server ). On android and web side thay are uploading audio file by normal put request with audio file in body. and even i am trying to upload it from postman but still its not working@SilverskyTechnology the server reponse with status code of 403 with message signature mismatch – Hunter Jan 28 '21 at 13:33
  • Response : i did try different methods (put, post and multipart) but still i am getting below response from server response >>> success("SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your Google secret key and signing method. – Hunter Jan 28 '21 at 13:58
  • "SignatureDoesNotMatch" indicates that you're doing something incorrect with the rest of the API, unrelated to putting the data (PUT does not require a signature). You are probably missing a required header, but it's possible your API requires some other format than raw data. To help you, we'd need access to your server's API documentation. It's unclear what you're doing on the Android side. – Rob Napier Jan 28 '21 at 19:46

3 Answers3

0

you can convert to base64 string and repeat call put if server can accept base64 request , if server can’t accept that you can’t. see documentation or contact server developer to find a way both can compatible.

Hamed Hosseini
  • 182
  • 2
  • 13
0

Create an URLRequest with a PUT method:

var request = URLRequest(url: url)
request.httpMethod = "PUT"

And then upload your data:

let task = URLSession.shared.uploadTask(with: request, from: data)
task.resume()

There's no need for a multipart if the server doesn't want hat.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • i did try this approach but got 403 response – Hunter Jan 29 '21 at 05:48
  • Your question is about how to PUT data, but your real problem is that you actual problem is around misusing this server API. We don't know what the server is, so probably can't help you without that without details of the API. – Rob Napier Jan 29 '21 at 14:06
0

Managed to resolved the issue using this this approach. Left the Content-Type empty

Alamofire image upload with PUT

Hunter
  • 31
  • 5