Search code examples
swiftalamofireipfs

Swift - Alamofire returns "Invalid request format." when I try to upload file to pinata


print(element) print following

error = "Invalid request format."

Although the response.result is success.

I don't know what to do... appreciate any help.

let request = AF.request("https://api.pinata.cloud/pinning/pinFileToIPFS",
          method: .post,
          parameters: data,
          encoding: JSONEncoding.default,
          headers: [
            "Content-Type": "multipart/form-data;boundary=nadeshiko_data_boundary",
            "pinata_api_key": "myAPIKey",
            "pinata_secret_api_key": "mySecretApiKey"
        ])
        request.responseString { response in
            print("responseString responseee", response)
            switch response.result {
            case .success(let element):
                print(element)
            case .failure(let error):
                print("failure", error)
            }
        }

Solution

  • I asked to pinata support.

    Turns out I was trying to upload JSON file where I have to upload a File.