1

使用这段代码仅用于访问我的 iOS 项目中的 Adob​​e 文件,但如何将我的图片上传到 Adob​​e Assets 云并保存。

    [[AdobeUXAssetBrowser sharedBrowser]popupFileBrowser:^(AdobeSelectionAssetArray *itemSelections) {
    NSLog(@"Selected a file"); 
    for(id item in itemSelections) {

        AdobeAsset *it = ((AdobeSelectionAsset *)item).selectedItem;

        NSLog(@"File name %@", it.name);
     [_statuslabel setText:fileDesc];

        //If an image, let's draw it locally
        NSString *fileType = ((AdobeAssetFile *)it).type;
        if([fileType isEqualToString:@"image/jpeg" ] || [fileType isEqualToString:@"image/png" ]) {
            NSLog(@"Going to download the image");
            [((AdobeAssetFile *)it) getData:NSOperationQueuePriorityHigh
                                 onProgress:^(double fractionCompleted) {
                                 }
                               onCompletion:^(NSData *data, BOOL fromcache) {
                                   NSLog(@"Done downloaded");
                                   UIImage *preview = [UIImage    imageWithData:data];
                               }
                             onCancellation:^(void){

                             }
                                    onError:^(NSError *error) {

                                    }
             ];

        }

    }
} onError:^(NSError *error)
{
     //do nothing
     NSLog(@"Error");
 }];
4

1 回答 1

1

您可以在此处找到有关如何使用 CreativeSDK 从 Creative Cloud 上传和下载文件的教程: https ://creativesdk.adobe.com/docs/ios/#/articles/files/index.html

特别是处理文件上传的代码如下:

NSData *imgData = UIImageJPEGRepresentation( yourImage, 0.8f );

NSString *dataPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"foo.jpg"];
NSURL *dataURL = [NSURL fileURLWithPath:dataPath];

NSError *err;
BOOL success = [imgData writeToFile:dataPath options:NSDataWritingAtomic error:&err];

if (success) {

    AdobeAssetFolder *root = [AdobeAssetFolder getRootOrderedByField:AdobeAssetFolderOrderByName orderDirection:AdobeAssetFolderOrderDescending];

    [AdobeAssetFile create:@"foo.jpg"
                  inFolder:root
              withDataPath:dataURL
                  withType:kMimeTypeJPEG
       withCollisionPolicy:AdobeAssetFileCollisionPolicyAppendUniqueNumber
                onProgress:^(double fractionCompleted) {
                    NSLog(@"Percent complete %f", fractionCompleted);
                }
              onCompletion:^(AdobeAssetFile *file) {
                  NSLog(@"Uploaded");
              }
            onCancellation:nil
                   onError:^(NSError *error) {
                       NSLog(@"error uploading %@", error);
                   }];
}
于 2015-03-07T06:54:44.880 回答