嗨,大家好:從亞馬遜S3在IOS下載文件我有從Amazon S3的URL有格式下載文件有問題
https://s3.amazonaws.com:443/[Something]/[filename] .MP3?簽名= [簽名] &過期= [有效期] & AWSAccessKeyId = [ACCESSID]
上面的網址只是一個格式,是保密的,所以我不能發佈一個實際的URL。
我使用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具有上述格式。如果是,如何? 在此先感謝您的幫助
因此,您已經記錄了您從調試器創建的URL,將該URL粘貼到瀏覽器中,並且它在瀏覽器中運行,但在應用程序中運行? –
是的,如果我在瀏覽器中打開網址,它會播放,但不會使用上面的代碼在應用程序中下載。 –
聽起來可能是ASI中的一個bug,那麼你還試過了其他什麼庫? –