1

こんにちは、Amazon s3 の URL から次の形式のファイルをダウンロードする際に問題が発生しています。

https://s3.amazonaws.com:443/[何か]/[ファイル名].mp3?Signature=[署名]&Expires=[有効期限]&AWSAccessKeyId=[アクセスID]

上記の URL は単なる形式であり機密情報であるため、実際の URL を掲載することはできません。

ASIHTTPRequest を使用してファイルをダウンロードしていますが、http ステータス コード 403 (禁止) と応答文字列が null として取得されます。

リンクをウェブブラウザのアドレスバーに貼り付けると、ブラウザが曲を再生します。

これはコードです:

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 を使用してファイルをダウンロードすることは可能です。はいの場合、どのように?助けてくれてありがとう

4

1 に答える 1

2

ご質問に対する直接的な回答ではないかもしれませんが、昨年活発な開発を停止した ASIHTTPRequest を使用するよりも、Amazon が提供するAWS SDK for iOSをそのまま使用する方が簡単ではないでしょうか?

于 2012-08-29T09:15:39.303 に答える