I have a upload form:
<form action="http://localhost/upload.php" method="post" enctype="multipart/form-data">
<input type="file" id="upload" name="upload" />
</form>
and php code to load the form:
isset($_FILES["upload"]) or die("Error");
if (move_uploaded_file($_FILES["upload"]["tmp_name"], $outputFile)) {
}
In xcode, Im creating a query as follows:
NSMutableURLRequest* request = [[AFHTTPRequestSerializer serializer]
multipartFormRequestWithMethod:@"POST"
URLString:@"http://localhost/upload.php"
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFormData:data name:@"somefilename.ext"];
} error:nil];
But it looks like I did it wrong, right?
UPDATE
Im new for AFNetworking, and I want to understand how it creates a multipart / form-data message as above. It seems that the code does not contain the input name "upload", therefore, it will not be able to pass the first line of the download php script. I read a document from AFNetworking GitHub, but they don't say anything about building form data with NSData, which is the case here.
source
share