samedi 25 juin 2016

how do I get NSURL for an image froom UIImagePickerController? for upload to Firebase


So there have been a few other threads started because people have trouble with this. like this one: Obtain NSURL from UIImagePickerController I am trying to follow this tutorial: https://firebase.google.com/docs/storage/ios/upload-files#upload_from_a_local_file

My video uploads work, just not images.

My video code is straightforward:

if mediaType.isEqualToString(kUTTypeMovie as String) {
        let videoURL = info[UIImagePickerControllerMediaURL] as? NSURL

        fileToUploadURL = videoURL!
    }

but my image code doesn't work. this is what i have ended up with:

        let imageUrl = info["UIImagePickerControllerReferenceURL"] as? NSURL

        let assets = PHAsset.fetchAssetsWithALAssetURLs([imageUrl!], options: nil)
        let asset = assets.firstObject
        asset?.requestContentEditingInputWithOptions(nil, completionHandler: { (contentEditingInput, info) in
            let imageFile = contentEditingInput?.fullSizeImageURL
            // now call putFile with imageFile instead of imageUrl
            self.fileToUploadURL = imageFile
        })

seems like no matter what I do I'm getting an error. this is my current error

2016-06-25 12:45:23.695 Chain[4187:1957121] Body file is unreachable: /var/mobile/Media/DCIM/100APPLE/IMG_0027.JPG
 Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_0027.JPG”       couldn’t be opened because you don’t have permission to view it."

CONSOLE LOG

2016-06-25 12:47:59.108 Chain[4187:1957121] Body file is unreachable: /var/mobile/Media/DCIM/100APPLE/IMG_0027.JPG Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_0027.JPG” couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///var/mobile/Media/DCIM/100APPLE/IMG_0027.JPG, NSFilePath=/var/mobile/Media/DCIM/100APPLE/IMG_0027.JPG, NSUnderlyingError=0x18b7ad40 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} 2016-06-25 12:48:02.969 Chain[4187:1957659] plugin com.swiftkey.SwiftKeyApp.Keyboard invalidated Optional(["public.image", "public.movie"]) info: ["UIImagePickerControllerOriginalImage": size {1836, 1454} orientation 0 scale 1.000000, "UIImagePickerControllerReferenceURL": assets-library://asset/asset.JPG?id=5FE3480C-0A3E-42B2-B83B-93D0F321A3B2&ext=JPG, "UIImagePickerControllerMediaType": public.image, "UIImagePickerControllerCropRect": NSRect: {{0, 0}, {1836, 1452}}, "UIImagePickerControllerEditedImage": size {638, 504} orientation 0 scale 1.000000] fileToUploadURL: file:///var/mobile/Media/DCIM/100APPLE/IMG_0027.JPG Optional(["public.image", "public.movie"]) 2016-06-25 13:01:58.845 Chain[4187:1958957] plugin com.swiftkey.SwiftKeyApp.Keyboard invalidated info: ["UIImagePickerControllerOriginalImage": size {1836, 1454} orientation 0 scale 1.000000, "UIImagePickerControllerReferenceURL": assets-library://asset/asset.JPG?id=CFF5692E-2B93-407D-A9E4-48AC1BEDCAF2&ext=JPG, "UIImagePickerControllerMediaType": public.image, "UIImagePickerControllerCropRect": NSRect: {{0, 0}, {1836, 1452}}, "UIImagePickerControllerEditedImage": size {638, 504} orientation 0 scale 1.000000] fileToUploadURL: nil

2016-06-25 13:04:05.136 Chain[4187:1957121] _BSMachError: (os/kern) invalid capability (20) 2016-06-25 13:04:05.138 Chain[4187:1959394] _BSMachError: (os/kern) invalid name (15) 2016-06-25 13:04:05.146 Chain[4187:1959394] plugin com.swiftkey.SwiftKeyApp.Keyboard invalidated 2016-06-25 13:04:05.220 Chain[4187:1957188] CFNetwork SSLHandshake failed (-9806) 2016-06-25 13:04:05.661 Chain[4187:1957121] Body file is unreachable: /var/mobile/Media/DCIM/100APPLE/IMG_0015.JPG Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_0015.JPG” couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///var/mobile/Media/DCIM/100APPLE/IMG_0015.JPG, NSFilePath=/var/mobile/Media/DCIM/100APPLE/IMG_0015.JPG, NSUnderlyingError=0x18bd4330 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}


Aucun commentaire:

Enregistrer un commentaire