我无法将视频上传到服务器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我无法将视频上传到服务器相关的知识,希望对你有一定的参考价值。
我尝试过所有内容,但每次尝试上传此视频时都会出现此错误。错误
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
我需要帮助!!!!
答案
我在上传视频时面临同样的问题。然而,云视频正在上传,因为手机内存中的视频面临错误。所有你需要做的而不是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];
});
}
}];
}
另一答案
我认为您需要在应用中请求权限才能加载视频。
尝试在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您必须具有info.plist中定义的权限。
- 使用requestPlayerItem函数中获取的url创建数据并将此数据作为参数传递给uploadVideo函数。我希望这对你有用。
以上是关于我无法将视频上传到服务器的主要内容,如果未能解决你的问题,请参考以下文章