2
私はiosを新しくしました。 画像や動画をPHPサーバに送る方法。私はキーを持っています"画像" の送信画像とキー"ビデオ"ビデオファイルを送信する。自分のキーでイメージやビデオを送信する必要があります。どうすれば送信できますか?Iosについては、目的のcキーでサーバーに画像やビデオを送信する方法
私はiosを新しくしました。 画像や動画をPHPサーバに送る方法。私はキーを持っています"画像" の送信画像とキー"ビデオ"ビデオファイルを送信する。自分のキーでイメージやビデオを送信する必要があります。どうすれば送信できますか?Iosについては、目的のcキーでサーバーに画像やビデオを送信する方法
Post
メソッドを使用してください。また、イメージ/ビデオをデータにアーカイブし、シートデータをサーバーに送信する必要があります。 Alamofireを使ってこれを行うことをお勧めします。これがコードです。あなたがOCに精通しているとして、ここ
let imageData = UIPNGRepresentation(image)!
Alamofire.upload(imageData, to: "https://httpbin.org/post").responseJSON { response in
debugPrint(response)
}
更新ではなくAFNetworkingを使用し、
です。これがコードです。ここで
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://example.com/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:[NSURL fileURLWithPath:@"file://path/to/image.jpg"] name:@"file" fileName:@"filename.jpg" mimeType:@"image/jpeg" error:nil];
} error:nil];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionUploadTask *uploadTask;
uploadTask = [manager
uploadTaskWithStreamedRequest:request
progress:^(NSProgress * _Nonnull uploadProgress) {
// This is not called back on the main queue.
// You are responsible for dispatching to the main queue for UI updates
dispatch_async(dispatch_get_main_queue(), ^{
//Update the progress view
[progressView setProgress:uploadProgress.fractionCompleted];
});
}
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"%@ %@", response, responseObject);
}
}];
[uploadTask resume];
は[AFNEtworking](https://github.com/AFNetworking/AFNetworking)の顔をしているさ! – Lion
はい、AFNEtworking ..をインポートする方法は? – Sasi
[iOSでのHTTP POSTリクエストの送信]の可能な複製(http://stackoverflow.com/questions/15749486/sending-an-http-post-request-on-ios) – SOFe