【发布时间】:2015-06-23 08:11:37
【问题描述】:
我有一个使用 azure 存储 blob 存储 jpg 照片的 IOS 应用程序。我的问题是在检索 blob 以进行显示时。
大多数情况下,它们都可以正常检索。但只是偶尔一个奇怪的不会被退回。而是返回 749 个字节,但错误仍然 = nil。
现在这样就好了,真的没问题。但是,此后每次我尝试再次检索该 blob 时都会出现相同的问题。 所有周围的 blob 都可以正常返回。有问题的 blob 很好,可以使用其他设备检索。
我花了很多时间清除所有涉及的变量并调用有问题的 blob,无论如何只返回 749 个字节。从设备中删除应用并重新安装是唯一的解决方法!
所以我认为 Azure 存储或移动服务认为返回的数据是正常的(因为它没有错误)并且继续发送相同的数据 - 我如何才能防止这种情况并要求真正重试?
下面的实际检索代码由 github 提供:谢谢 Ajayi13,它几乎很棒
[request fetchDataWithBlock:^(NSData* data, NSError* error)
{
if(error)
{
if(block)
{
block(nil, error);
}
else if([(NSObject*)_delegate respondsToSelector:@selector(storageClient:didFailRequest:withError:)])
{
[_delegate storageClient:self didFailRequest:request withError:error];
}
return;
}
if(block)
{
block(data, nil);
}
else if([(NSObject*)_delegate respondsToSelector:@selector(storageClient:didGetBlobData:blob:)])
{
[_delegate storageClient:self didGetBlobData:data blob:blob];
}
}];
我现在根据 AdamSorrin 的回复和 DANIEL PASCO 的博客文章添加了以下代码:https://blackpixel.com/writing/2012/05/caching-and-nsurlconnection.html
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)[cachedResponse response];
// Look up the cache policy used in our request
if([connection currentRequest].cachePolicy == NSURLRequestUseProtocolCachePolicy) {
NSDictionary *headers = [httpResponse allHeaderFields];
NSString *cacheControl = [headers valueForKey:@"Cache-Control"];
NSString *expires = [headers valueForKey:@"Expires"];
if((cacheControl == nil) && (expires == nil)) {
NSLog(@"server does not provide expiration information and we are using NSURLRequestUseProtocolCachePolicy");
return nil; // don't cache this
}
}
return nil;
}
但这并没有解决我的问题 :o(
【问题讨论】:
-
能否链接到您正在使用的 GitHub 代码,或者将其包含在问题中?
-
嗨 lindydonna,我正在使用的代码可以在 github.com/Ajayi13/BlobExample-Swift 找到。谢谢
标签: objective-c azure-storage azure-mobile-services azure-blob-storage