Behrouz Riahi
Behrouz Riahi

Reputation: 1791

How to get the image path stored in the iCloud?

I am using TLPhotoPicker to allow the user to choose multiple images. I want to upload the images to Firebase and based on their documentation, I need to retrieve the image's path.

@Eridana answer here, which is as follows:

PHImageManager.default().requestImageData(for: selectedAssets[0].phAsset!, options: PHImageRequestOptions(), resultHandler:
            {
                (imagedata, dataUTI, orientation, info) in
                if info!.keys.contains(NSString(string: "PHImageFileURLKey"))
                {
                    let path = info![NSString(string: "PHImageFileURLKey")] as! NSURL
                    print(path)
                } else {

                }
        })

Works and prints the local image's path in the device (file:///var/mobile/Media/DCIM/100APPLE/IMG_0005.PNG), but when I choose images stored in the iCloud, I get the following error printed to the console:

2017-11-04 18:17:44.423826+0400 tourPlacesApp[242:8831] [Generic] Failed to load image data for asset C2717B20-5180-4CE8-AFEB-D661C259D227/L0/001 mediaType=1/0, sourceType=1, (2448x3264), creationDate=2017-07-02 06:46:00 +0000, location=1, hidden=0, favorite=0 with format 9999

When I looked online, I found that I have to store the metadata of the images first inside local file and only then I will be able to get the image path.

How do I get the metadata from the images stored as PHAsset

EDIT

It says in Apple docs that I need to download the image if it is in the iCloud, but I couldn't find where they explain how to download the image.

Upvotes: 0

Views: 903

Answers (1)

Vijay sharma
Vijay sharma

Reputation: 1

The solution is, in your TLPhotosPickerViewController.swift class first search for cloud and then uncomment all methods and variables related to cloud, specially requestCloudDownload(asset: asset, indexPath: indexPath) method

Upvotes: 0

Related Questions