gpt4 book ai didi

iphone - 通过 XML 从 iPhone 向 App Engine 发送图像

转载 作者:行者123 更新时间:2023-12-03 21:10:18 26 4
gpt4 key购买 nike

我正在尝试从我的 iPhone 应用程序将一个小图像以及一些 XML 信息发送到 App Engine。我在沿途某个地方的图像遇到问题。没有给出错误,数据正在传输到 Datastore Viewer 中的 Blob 条目,但 App Engine 上的 Blob 文件不会出现在 Blob Viewer 中。我怀疑图像在 App Engine 中的一项转换中被搞乱了,或者没有在 App Engine 中存储为正确的类型。你觉得怎么样?

在 iPhone 上,以下是对图像进行编码(使用标准 base64Encoding 函数)并将其添加到 GDataXMLElement 的相关部分,然后将其添加到 GDataXMLDoc 并通过 ASIHTTPRequest 发送:

NSString *dataString = [self.data base64Encoding];
GDataXMLElement *tempXMLElement = [GDataXMLElement elementWithName:@"data" stringValue: dataString];
[imageElement addChild: tempXMLElement];

ASIHTTPRequest 部分:

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL: url]; 
[request setDelegate: self];
[request addRequestHeader:@"User-Agent" value: [NSString stringWithFormat:@"MyApp:%@", version]];
[request addRequestHeader:@"Content-Type" value:@"text/xml"];
[request setShouldStreamPostDataFromDisk:YES];
[request appendPostDataFromFile: path];
[request start];

在 Python 中的 App Engine 上(很可能是问题所在):

image_data_xml_element = image_xml_node.getElementsByTagName("data")[0]
image_data_base64_unicode = image_data_xml_element.firstChild.data
image_data_base64_ascii = image_data_unicode.encode("utf8")
image_data_string = binascii.a2b_base64(image_data_base64_ascii)
new_image.data = db.Blob(image_data_string)

此外我还尝试过:

image_data_xml_element = image_xml_node.getElementsByTagName("data")[0]
image_data_base64_unicode = image_data_xml_element.firstChild.data
image_data_string = base64.b64decode(image_data_base64_unicode)
new_image.data = db.Blob(image_data_string)

编辑:为了完整起见,这是我正在使用的 Objective-C Base64 库 - 它看起来不像我预期的那样:

static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- (NSString *)base64Encoding;{
if ([self length] == 0)
return @"";

char *characters = malloc((([self length] + 2) / 3) * 4);
if (characters == NULL)
return nil;
NSUInteger length = 0;
NSUInteger i = 0;
while (i < [self length]){
char buffer[3] = {0,0,0};
short bufferLength = 0;
while (bufferLength < 3 && i < [self length])
buffer[bufferLength++] = ((char *)[self bytes])[i++];

// Encode the bytes in the buffer to four characters, including padding "=" characters if necessary.
characters[length++] = encodingTable[(buffer[0] & 0xFC) >> 2];
characters[length++] = encodingTable[((buffer[0] & 0x03) << 4) | ((buffer[1] & 0xF0) >> 4)];
if (bufferLength > 1)
characters[length++] = encodingTable[((buffer[1] & 0x0F) << 2) | ((buffer[2] & 0xC0) >> 6)];
else characters[length++] = '=';
if (bufferLength > 2)
characters[length++] = encodingTable[buffer[2] & 0x3F];
else characters[length++] = '=';
}

return [[[NSString alloc] initWithBytesNoCopy:characters length:length encoding:NSASCIIStringEncoding freeWhenDone:YES] autorelease];
}

最佳答案

Blob 查看器显示使用 Blobstore API 上传的文件,而不是添加到 Blob 属性中的常规数据存储实体的文件。

关于iphone - 通过 XML 从 iPhone 向 App Engine 发送图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3692697/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com