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

时间:2017-09-06 04:54:36

标签: ios iphone swift parse-platform swift3

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

  

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 /移动/媒体/ DCIM / 101APPLE / IMG_1773.MOV,   NSUnderlyingError = 0x174254280 {错误域= NSPOSIXErrorDomain代码= 1   “不允许操作”}}

     

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

我需要帮助!!!!

3 个答案:

答案 0 :(得分:1)

我在上传视频时遇到了同样的问题。对于云视频,正在上传,但是对于手机内存中的视频却遇到错误。您要做的所有事情(而不是网址路径)都将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];
                    });
                }
            }];
            }

答案 1 :(得分: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>

也许这会有效。

答案 2 :(得分:-1)

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

1您必须在info.plist中定义权限。

  1. 使用requestPlayerItem函数中获取的url创建数据并将此数据作为参数传递给uploadVideo函数。我希望这对你有用。