0
votes

I tried everything but every time I try to upload this video I got this error. Error

Domain=NSCocoaErrorDomain Code=257 "The file “IMG_1773.MOV” couldn’t be opened because you don’t have permission to view it."

[![fileprivate func getVideoFromasset() {
                let imgManager = PHImageManager.default()
                let fetchVideos = PHVideoRequestOptions()
                fetchVideos.isNetworkAccessAllowed = true
                fetchVideos.deliveryMode = .automatic

                guard let asset = self.videoAsset else {
                    return
                }

                imgManager.requestPlayerItem(forVideo: asset, options: fetchVideos, resultHandler: { (data, info) in
                    guard let video = data?.asset as? AVURLAsset else { return }
                    print(video.url)
                    self.urlAsset = video.url
                    self.getVideoFromUrl(url: video.url)
                })
            }
     @objc fileprivate func UploadVideo() {

            guard let url = self.urlAsset else {return}
            print(url.absoluteString)
            if self.videoUrl == nil {

                do {
                let filedat = try Data(contentsOf: url)
                let pffile = PFFile(name: "sdsd", data: filedat)
                    pffile?.saveInBackground({ (data, error) in
                        print(error)
                    }, progressBlock: { (intt) in
                        print(intt)
                    })
                } catch {
                    print(error)
                }
            } else {
                print(self.videoUrl)
                print("upload from url file")
            }
        }][1]][1]

Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_1773.MOV” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/var/mobile/Media/DCIM/101APPLE/IMG_1773.MOV, NSUnderlyingError=0x174254280 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

file:///var/mobile/Media/DCIM/101APPLE/IMG_1773.MOV

I need help!!!!

2
Try to clean xcode!Salman Ghumsani
i did. but it didnt work\os-lopez-ne

2 Answers

1
votes

I faced same issue for uploading video. For cloud video was uploading however for videos which are in phone memory faced error. All you need to do rather than Url path use NSData for videos which are not from cloud. Hope this is helpful. Thank you.

   [[PHImageManager defaultManager] requestAVAssetForVideo:selectedImage
                                                            options:options
                                                      resultHandler:
             ^(AVAsset * _Nullable avasset,
               AVAudioMix * _Nullable audioMix,
               NSDictionary * _Nullable info)
            {
                AVURLAsset *avurlasset = (AVURLAsset*) avasset;
                NSData *data = [NSData dataWithContentsOfURL:avurlasset.URL];
                AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:avurlasset.URL options:nil];
                AVAssetImageGenerator *generate1 = [[AVAssetImageGenerator alloc] initWithAsset:asset1];
                generate1.appliesPreferredTrackTransform = YES;
                NSError *err = NULL;
                CMTime time = CMTimeMake(1, 2);
                CGImageRef oneRef = [generate1 copyCGImageAtTime:time actualTime:NULL error:&err];
                UIImage *thumbNailImage = [[UIImage alloc] initWithCGImage:oneRef];

                NSString *typeOfImage = @"storingVideoPath";
                NSMutableDictionary  *dictForImagePath = [[NSMutableDictionary alloc] init];



                [dictForImagePath setValue:flStrForObj(selectedImage.localIdentifier) forKey:@"uniqueIdenifierForAsset"];
                [dictForImagePath setObject:indexPath forKey:@"indexPath"];
                [dictForImagePath setValue:typeOfImage forKey:@"imageType"];
                [dictForImagePath setValue:data forKey:@"imageValue"];
                [dictForImagePath setObject:thumbNailImage forKey:@"thumnailImage"];
                if(![arrayOfLibImages containsObject:dictForImagePath]) {
                    [arrayOfLibImages addObject:dictForImagePath];
                    dispatch_async(dispatch_get_main_queue(), ^{
                    [self.collectionViewForPickedPhotos reloadData];
                    });
                }
            }];
            }
-1
votes

There are few points necessary to be checked before video/image upload.

1 You must have permission defined in info.plist.

  1. Use the url obtained in requestPlayerItem function to create data and pass this data to uploadVideo function as a argument. I hope this will work for you.