我想从 URL 中获取图像:
http://imgur.com/gallery/ihHQvP1
然后将其转换为 NSData 以便我能够将其解析到服务器。服务器只接受 NSData 而不是图像链接。我从相机中得到以下信息:
NSData *pictureData = UIImagePNGRepresentation([self scaleImage:activityImageView.image toSize:CGSizeMake(230, 230)]);
然后将其放入 JSON 格式发送到服务器:
jsonPostBody= [NSString stringWithFormat:@"{\"activity_id\":\"%@\",\"user_id\":\"%@\",\"activity_title\":\"%@\",\"activity_category_id\":\"%@\",\"activity_description\":\"%@\",\"activity_image\":\"%@\",\"activity_begindate\":\"%@\",\"activity_enddate\":\"%@\", \"activity_time\":\"%@\", \"activity_email\":\"%@\",\"activity_city\":\"%@\",\"activity_where\":\"%@\",\"gotooffer_url\":\"%@\",\"latitude\":\"%@\",\"longitude\":\"%@\"}",[editActivityDict valueForKey:@"activity_id"],singletonObj.userID,title,selectedCategoryString,discription,[Base64 encode:pictureData],begindateConvert,enddateConvert,milatryTime,@"",city,where,entersite,singletonObj.singletonlatitude,singletonObj.singletonlogitude];
NSString *urlString=[NSString stringWithFormat:@"%@%@",ROOT_URL,EDIT_ACTIVITY];
如您所见,正文中发送的图片的变量是:
[Base64 encode:pictureData]
有任何想法吗?