ios - Alamofire failing to upload a file to Google Cloud Storage -


i'm trying upload media file gcs(google cloud storage) via alamofire. below code.

   let soundurl = url(fileurlwithpath: dirpaths.appending("/audio-file.wav"))      let headers: httpheaders = [         "content-type": "audio/wav",         "authorization": "bearer <mytoken>"     ]       alamofire.upload(         multipartformdata: { multipartformdata in             multipartformdata.append(soundurl, withname: "name")     },         to: "https://www.googleapis.com/upload/storage/v1/b/<folder-name>/o?uploadtype=media?&name=audio-file.wav",method: .post, headers: headers,         encodingcompletion: { encodingresult in             switch encodingresult {             case .success(let upload, _, _):                 upload.responsestring(completionhandler: { (response) in                     print(response)                 })              case .failure(let encodingerror):             print(encodingerror)              }           }     ) 

but it's not getting success.

the same thing tried in postman. , it works fine.. checked post request https://requestb.in both looks similar.

not sure problem.

update -

do need authorization token ios? because got token terminal. , put in header. guess it's okay right?

you've set uploadtype=media, looks you're doing multipart upload. if want upload media, don't multipart upload. if want multipart upload, set uploadtype=multipart. getting multipart upload work require upload has 2 parts, first of must json document describing resource, , second media.

these 2 upload mechanisms described here: https://cloud.google.com/storage/docs/json_api/v1/how-tos/multipart-upload


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -