1

アプリで生成した画像を Dropbox にアップロードしたいと考えています。DBRestClient からのアップロード メソッドが表示されますが、アップロード メソッドを呼び出す前にイメージを一時ファイルに書き込む必要があるようです。

メモリ内のオブジェクトからファイルをアップロードする方法はありますか? このようなもの:

UIimage *myImage = [[UIImage alloc]....
//
// Here I create the image on my app
//
NSData *myData = UIImageJPEGRepresentation(myImage, 1.0);
DBRestClient *rc = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
self.restClient = rc;
[rc release];
self.restClient.delegate = self;
[self.restClient uploadFile:@"myImage.jpg" toPath:@"DropBoxPath" fromPath:myData];
4

2 に答える 2

3

DBRestClient のヘッダーは明らかにするだけです

/* Uploads a file that will be named filename to the given root/path on the server. It will upload
   the contents of the file at sourcePath */
- (void)uploadFile:(NSString*)filename toPath:(NSString*)path fromPath:(NSString *)sourcePath;

iPhoneにはディスクがあるので、指定された方法で画像をtmpファイルとしてアップロードし、後で削除しますか? そのために、 NSData の writeToFile :atomically :またはwriteToFile:options:error:を使用できます。

于 2011-03-23T17:16:59.307 に答える
3

それが私がソリューションを実装した方法です:

- (void) uploadToDropBox {
    self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
    self.restClient.delegate = self;
    [self.restClient createFolder:dropBoxFolder];

    NSString *fileName = @"myImage.png"; 
    NSString *tempDir = NSTemporaryDirectory();
    NSString *imagePath = [tempDir stringByAppendingPathComponent:fileName];

    NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(self.loadQRCodeImage.image)];
    [imageData writeToFile:imagePath atomically:YES];

    [self.restClient uploadFile:fileName toPath:dropBoxFolder fromPath:imagePath];
}
于 2011-03-26T21:16:52.017 に答える