I have a video upload system in an iOS app using NSURLSessionUploadTask. The video file is saved to an NSURL so I am using the following code in my upload method:
I have a PHP server (using Laravel) running under nginx to handle this upload. I have tested it with Postman, and it accepts uploads fine (expecting a file under the name "file").
When I run the above objc code, the server tells me that no file has been uploaded (the $_FILES array is empty).
I have tried with and without setting the "fileName" header, and I've tried setting "Content-Type" to "multipart/form-data" but none of these works.
How can I get NSURLSessionUploadTask to properly upload these files (from an NSURL) to the server?
Code:
request.HTTPMethod = @"POST";
[request addValue:@"file" forHTTPHeaderField:@"fileName"];
// Create upload task
NSURLSessionUploadTask *task = [session uploadTaskWithRequest:request fromFile:filePath completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if(!error) {
// handle success
} else {
// handle error
}
}];
// Run the task
[task resume];
I have a PHP server (using Laravel) running under nginx to handle this upload. I have tested it with Postman, and it accepts uploads fine (expecting a file under the name "file").
When I run the above objc code, the server tells me that no file has been uploaded (the $_FILES array is empty).
I have tried with and without setting the "fileName" header, and I've tried setting "Content-Type" to "multipart/form-data" but none of these works.
How can I get NSURLSessionUploadTask to properly upload these files (from an NSURL) to the server?