1

ドロップボックス フォルダーに .plist としてアップロードしたい xml 文字列があります。

現在、NSDictionaryを作成して一時フォルダーを作成し、その一時フォルダーに辞書をplistとして書き込み、その一時フォルダーにある.plistをドロップボックスにアップロードします。

これは良いプログラミング ソリューションではないと思います。

これは正常に動作します

if([title isEqualToString:@"Upload to Dropbox"])
    {


        //pass string in memory to nsdictionary
        NSData * data = [_uploadPlistString dataUsingEncoding:NSUTF8StringEncoding];
        NSString *errorDesc = nil;
        NSPropertyListFormat format;
        NSDictionary *uploadFile= (NSDictionary*)[NSPropertyListSerialization
                                         propertyListFromData:data
                                         mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                         format:&format
                                         errorDescription:&errorDesc];


        //create a temp folder
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"temp"];
        NSLog(@"documents datapath: %@",dataPath);
        //check if folder exist
        NSError *error = nil;
        if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
            [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder



        //write dictionary to plist
        NSString *pathTemp = [dataPath stringByAppendingPathComponent:@"agenda.plist"];
        // write plist to disk
        [uploadFile writeToFile:pathTemp atomically:YES];


        //get last created file name from singleton
        SingletonClass *sharedInstance=[SingletonClass sharedInstance];
        NSString *destDirectory= sharedInstance.lastCreatedFolderName;

        //set file name for dropbox
        NSString *filename = @"agenda.plist";
        [[self restClient] uploadFile:filename toPath:destDirectory
                        withParentRev:nil fromPath:pathTemp];


    }

しかし、メモリ内にある NSDictionary を直接 Dropbox にアップロードするにはどうすればよいですか?

バンドルなどに書き込むことなく。

4

1 に答える 1

0

Dropbox SDK のパブリック API は、ファイルからの直接アップロードのみをサポートしています。

ただし、SDK はオープン ソースであるため、簡単に拡張できます。

メインのアップロードは

- (void)uploadFile:(NSString*)filename toPath:(NSString*)path fromPath:(NSString *)sourcePath
params:(NSDictionary *)params

DBRestClient.m で。

DBRestClient にカテゴリを追加し、ファイル パスの代わりに NSData を使用するアップロード用の同様のメソッドを追加できます。

実装のほとんどをコピーできますが、ファイル名の代わりに NSData を使用します。ドロップボックスでのファイル名の生成方法を変更し、ファイルの代わりに NSData を使用して NSInputStream をインスタンス化します。

辞書から NSData を取得するには、NSKeyedArchiver を使用できます。

于 2012-11-08T20:21:28.270 に答える