从目标C传递self.request.get(" profile_pic")Null

时间:2014-10-10 20:24:53

标签: python objective-c webapp2

我无法弄清楚如何检查这是通过POST从Objective-C传递Null

在Objective-C中:

NSData *profile_pic_data = nil; (this does not change)
...
//Profile Pic Data
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"profile_pic\"; filename=\"profile_pic.jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:profile_pic_data]];
...
NSLog(@"profile_pic_data = %@", profile_pic_data); //RETURNS (null)

在Python中:

...
user_profile_pic_data = self.request.get("profile_pic")
...
if user_profile_pic_data:
   #IT RUNS THIS CODE
else:
   #IT SHOULD RUN THIS CODE

如果我在self.request.get(" profile_pic")之后打印出user_profile_pic_data,它就不会显示任何内容。

我试过了:

if user_profile_pic_data:
if user_profile_pic_data is not NONE:
if user_profile_pic_data is not NONE and != '':

似乎没什么用。

有人经历过这个吗?

1 个答案:

答案 0 :(得分:0)

不确定你到底想要在这里完成什么,但是在这里:

NSData *profile_pic_data = nil;

您将profile_pic_data设置为nil。然后,您将POST数据附加到body,然后再次进行NSLogging profile_pic_data。由于您实际上从未将其设置为除nil以外的任何其他内容,这就是为什么它输出为无效。

也许您希望profile_pic_data实际拥有内容?您可以使用

UIImage填充它
NSData *profile_pic_data = UIImageJPEGRepresentation(anImage);