简体   繁体   English

转换iPhone IOS视频文件上传器以使用存储在文档目录中的文件

[英]Converting an iPhone IOS Video File Uploader to work with a file stored in document directory

This is my first real project. 这是我的第一个实际项目。 I have an app that captures several seconds of video using AVFoundation, outputs this to a file in the documents directory and lets the user preview the video before they upload it using HTTP and a PHP script on my website. 我有一个应用程序,可以使用AVFoundation捕获几秒钟的视频,并将其输出到documents目录中的文件,并允许用户预览视频,然后再使用HTTP和PHP脚本在我的网站上上传视频。

All the video capture and preview work perfectly but I am stuck on uploading the video file. 所有的视频捕获和预览都可以完美地工作,但是我仍然无法上传视频文件。

I learnt a lot from this simpleSDK video which shows how to achieve the desired effect using a video file stored in the apps main bundle. 我从这个simpleSDK视频中学到了很多东西,该视频展示了如何使用存储在apps主捆绑包中的视频文件来达到所需的效果。

The code from the tutorial that set up videoData ready to upload originally looked like this: 本教程中设置的VideoData可以直接上传的代码如下所示:

NSData *videoData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"mov"]];
NSString *urlString = @"http://www.iphonedevnation.com/video-tutorial/upload.php";

The filename of the video file that I need to upload is always unique and generated using CFUUIDCreateString. 我需要上传的视频文件的文件名始终是唯一的,并且是使用CFUUIDCreateString生成的。 I join this string to the path for the documents directory, add ".mov" to the end of it and save it into a text file for retrieving later. 我将此字符串连接到documents目录的路径,在其末尾添加“ .mov”,并将其保存到文本文件中以供以后检索。

This all works as I am able to retrieve the filename from the file and use it to preview the movie clip elsewhere in the app. 由于我能够从文件中检索文件名并使用它在应用程序中的其他位置预览影片剪辑,因此所有这些都可以正常工作。

My path is in an NSString, that I have tried converting to NSURL and removing the file suffix to get it to work with the NSData *videoData.........line but it doesn't compile, I get an "No known class method for selector 'dataWithContentsOfFile:ofType.' 我的路径在NSString中,我尝试将其转换为NSURL并删除文件后缀以使其与NSData * videoData .........行一起使用,但未编译,我得到了“选择器'dataWithContentsOfFile:ofType'的未知类方法。 error. I am targeting iOS 5 and using Xcode 4.3 with ARC and Storyboards. 错误。我的目标是iOS 5,并将Xcode 4.3与ARC和Storyboards一起使用。

I've been at this for best part of 5 hours now so hopefully someone can help. 我已经在这里呆了5个小时了,所以希望有人能帮上忙。 My code, which included tips from elsewhere on converting from a NSString to NSURL follows: 我的代码包括从其他地方转换为NSString到NSURL的技巧,如下所示:

NSString *content = [[NSString alloc] initWithContentsOfFile:lastSavedTalentFilenamePath 
              usedEncoding:nil
              error:nil];

NSLog(@"content=%@",content);

//Need to now remove the '.mov' file type identifier
NSString *shortContent= [content substringToIndex:[content length]-4];
NSLog(@"***************shortContent***************%@", shortContent);

NSURL *convertedContent = [NSURL fileURLWithPath:shortContent];
NSLog(@"***************convertedContent***********%@",convertedContent);

NSData *videoData = [NSData dataWithContentsOfFile:convertedContent ofType:@"mov"];];

There is no NSData method called dataWithContentsOfFile:ofType: 没有名为dataWithContentsOfFile:ofType的NSData方法:

The methods available are: 可用的方法有:

+ dataWithContentsOfFile:
+ dataWithContentsOfFile:options:error:

both of which take the file location as an NSString so there's not need to convert to an NSURL 两者都将文件位置作为NSString,因此无需转换为NSURL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式检测存储在文档目录中的音频文件是否可播放Xcode iPhone - How to detect whether an audio file stored in document directory is playable or not programmatically Xcode iPhone 如何将视频文件保存到文档目录中 - how to save video file into document directory 在ios中压缩doc文件并将其保存到文档目录 - Zip the doc file in ios and save in to document directory 如何将图像文件从文档目录上传到iPhone中的php服务器 - how to upload image file from document directory to php server in iphone iphone:从文档目录文件夹中复制或移动文件 - iphone: copy or move file from document directory folder 如何从iPhone的文档目录中读取pdf文件? - How to read pdf file from document directory in iPhone? 如何在iPhone中使用时间戳从文档目录读取pdf文件? - How to read pdf file from document directory with timestamp in iPhone? 在iPhone中通过Web服务上传pdf文件(从文档目录)? - Upload pdf file (from document directory) through web service in iPhone? 关于用于iOS开发的图像和文件上传器的建议示例 - Suggestion Example on image and file uploader for ios development iPhone-如何检查文件是目录,音频,视频还是图像? - iphone - how to check if the file is a directory , audio , video or image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM