Search code examples
iosiphoneios7adobecreativesdk

Can we upload photos in Adobe Assets using Abode Creative SDK for iOS and Android?


Using this chunk of code only for accessing the Adobe files in my iOS project, but how can I upload my pictures in Adobe Assets cloud and save it.

    [[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");
 }];

Solution

  • You can find a tutorial on how to upload and download files from Creative Cloud using the CreativeSDK here: https://creativesdk.adobe.com/docs/ios/#/articles/files/index.html

    The code in particular that deals with file uploads is below:

    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);
                       }];
    }