我无法将视频上传到服务器

问题描述 投票:0回答:3

我尝试过所有内容,但每次尝试上传此视频时都会出现此错误。错误

Domain = NSCocoaErrorDomain Code = 257“无法打开文件”IMG_1773.MOV“,因为您无权查看它。”

[![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]

错误域= NSCocoaErrorDomain代码= 257“无法打开文件”IMG_1773.MOV“,因为您无权查看它。” UserInfo = {NSFilePath = / var / mobile / Media / DCIM / 101APPLE / IMG_1773.MOV,NSUnderlyingError = 0x174254280 {Error Domain = NSPOSIXErrorDomain Code = 1“不允许操作”}}

文件:///var/mobile/Media/DCIM/101APPLE/IMG_1773.MOV

我需要帮助!!!!

ios iphone swift parse-platform swift3
3个回答
1
投票

我在上传视频时面临同样的问题。然而,云视频正在上传,因为手机内存中的视频面临错误。所有你需要做的而不是Url路径使用NSData的视频不是来自云。希望这是有帮助的。谢谢。

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

0
投票

我认为您需要在应用中请求权限才能加载视频。

尝试在info.plist文件中添加这样的内容:

<key>NSCameraUsageDescription</key>
<string>Description why you need the permission</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Description why you need the permission</string>

也许这会起作用。


-1
投票

在视频/图像上传之前,需要检查几点。

1您必须具有info.plist中定义的权限。

  1. 使用requestPlayerItem函数中获取的url创建数据并将此数据作为参数传递给uploadVideo函数。我希望这对你有用。
© www.soinside.com 2019 - 2024. All rights reserved.