大家好,我在从 amazon s3 url 下载文件时遇到问题,其格式为:
https://s3.amazonaws.com:443/[Something]/[filename].mp3?Signature=[signature]&Expires=[Expiry]&AWSAccessKeyId=[AccessID]
上面的网址只是一种格式并且是保密的,所以我不能发布实际的网址。
我正在使用 ASIHTTPRequest 下载文件,但获取 http 状态代码 403(禁止)和响应字符串为空。
当我将链接粘贴到网络浏览器的地址栏中时,浏览器会播放歌曲。
这是代码:
if (!networkQueue) {
networkQueue = [ASINetworkQueue queue];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
ASIHTTPRequest *downloadRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[mediaUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ]];
[downloadRequest setRequestMethod:@"GET"];
[downloadRequest setShouldRedirect:YES];
NSString *fileName = [NSString stringWithFormat:@"%@.mp3",[dict valueForKey:@"ID"]];
fileName = [fileName stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *filePath = [NSString stringWithFormat:@"%@/%@",documentsDirectory,fileName];
NSLog(@"File Path: %@",filePath);
[downloadRequest setDownloadDestinationPath:filePath];
[downloadRequest setDownloadProgressDelegate:[downloadView viewWithTag:2]];
[downloadRequest setDelegate:self];
[downloadRequest setDidFinishSelector:@selector(downloadFinished:)];
[downloadRequest setDidFailSelector:@selector(downloadFailed:)];
[networkQueue addOperation:downloadRequest];
[networkQueue go];
是否可以使用 amazon s3 url 下载具有上述格式的文件。如果是,如何?提前感谢您的帮助