-1


取得しているサーバーから画像をダウンロードNSDataしてローカルパスに保存するURLが1つあります。

thedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[CNPlayerURL getUniqueIdAvailable],imageUrl]]];

[thedata writeToFile:localFilePath atomically:YES];

今私の質問は、パスに保存しているイメージの名前と拡張子をダウンロードできますか?localFilePathドキュメントディレクトリのパスにimagenameを追加しているためです(.jpg拡張子が付いた一意のIDを1つ指定しています)

ブラウザでURLを使用するときのように

http:/myserverurl/groupid/199/blob

この画像をダウンロードしています:

ここに画像の説明を入力してください

今、私はこの名前と拡張子で保存したい

4

2 に答える 2

1
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *jpgFilePath = [NSString stringWithFormat:@"/%@/%@", YourDirectoryName,[imageUrl lastPathComponent]];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:jpgFilePath];
NSFileManager *fileManager = [NSFileManager defaultManager];

    if (![fileManager fileExistsAtPath:getImagePath]) {
        NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
        [data1 writeToFile:getImagePath atomically:YES];
    }
于 2013-03-07T11:54:38.660 に答える
1

suggestedFilenameこのような方法で「ダウンロード可能なファイル名」を取得できますNSURLResponse

-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    NSLog(@"Downloadable FileName: %@",[response suggestedFilename]);
    NSLog(@"Downloadable MIMEType: %@",[response MIMEType]);
    NSLog(@"Downloadable ContentLength: %lld",[response expectedContentLength]);
    [webData setLength:0];
}
于 2013-03-08T05:33:51.963 に答える