Firemaps's avatar

Debugging multipart-form post requests from iOS to live project

I am trying to post an image from iOS to a live project with Alamofire 4 and Swift 3

Other post requests eg login work fine

However although I can get http 200 and see a large data object, I am unable to see any error messages when I try to return $request; for example.

// routes 

Route::post('/store', [
    'uses' => 'iOSController',
    'as'     => 'apiv1.store'
]);
// iOSController

public function store(Request $request) {

      return $request;

}

In swift :


// var image = UIImage() is set and ready for upload. Have UIImage, imagePath, NSData, etc.

// button pressed
        let URL = try! URLRequest(url: "https://website.com/apiv1/store", method: .post)
        
        Alamofire.upload(multipartFormData: { multipartFormData in
            
            multipartFormData.append(UIImagePNGRepresentation(self.image!)!, withName: "testing", fileName: "test.png", mimeType: "image/png")
            
        }, with: URL, encodingCompletion: {
            encodingResult in
            switch encodingResult {
            case .success(let upload, _, _):
                upload.responseData { response in
                    debugPrint("SUCCESS RESPONSE: \(response)")
                    print(response.response!)
                    print(response.data)
                    print(response.metrics)

                    // this gets http 200
                    // I can see there is a large response.data object 
                    // the laravel debugging page is normally included here but with multipart upload it is not included
                   
                }
            case .failure(let encodingError):
                print("ERROR RESPONSE: \(encodingError)")
            }
        })

Anyone know how I can upload image from iOS -> Laravel, move the image to a specific folder and create a row in db? Works fine for me on web-app.

Cheers

0 likes
1 reply
Firemaps's avatar

Update:

Trying to hit dropzone inside form tags, not working either

Current error = _kCFStreamErrorDomainKey=1, NSErrorPeerAddressKey

Please or to participate in this conversation.