我使用以下代码实现从 UIImagePickerController 选择上传图像到服务器(使用 AFNETWorking 库):
NSURL *url = [NSURL URLWithString:@"http://url"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
UIImage *imageIWantToUpload = imageupload;
NSData *dataToUpload = UIImageJPEGRepresentation(imageIWantToUpload, 0.5);
// Create the NSData object for the upload process
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"iosuploads.php" parameters:nil constructingBodyWithBlock: ^(id<AFMultipartFormData> formData) {
NSLog(@"strimng");
[formData appendPartWithFileData:dataToUpload name:@"uploadedfile" fileName:@"attachment.jpg" mimeType:@"image/jpeg"];
NSLog(@"strimng");
}];
NSLog(@"strimng");
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[httpClient enqueueHTTPRequestOperation:operation];
当我在 iphone 上构建并运行它时,在控制台中显示图像上传的大小,但在服务器中找不到刚刚上传的图像。
我在 000webhost 中创建帐户进行测试,但我在其中使用帐户 FTP 进行测试。我不知道我必须使用什么 URL 来上传文件?
你能帮助我吗?谢谢