我们如何在 ASIHTTPRequest 中发布视频和图像?
我想将一张图像发布到我的网络服务和一个视频,但问题是,当它转到视频部分时,它会给我过度错误
NSString *url = [NSString stringWithFormat:@"http://example.com/add_videoxml.php"];
networkQueue = [[ASINetworkQueue alloc] init];
[networkQueue cancelAllOperations];
[networkQueue setShowAccurateProgress:YES];
//[networkQueue setUploadProgressDelegate:progressBar];
[networkQueue setDelegate:self];
[networkQueue setRequestDidFinishSelector:@selector(requestFinished:)];
[networkQueue setRequestDidFailSelector: @selector(requestFailed:)];
request= [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:url]] ;
[request setPostValue:@"284" forKey:@"id"];
[request setPostValue:@"show" forKey:@"show"];
[request addRequestHeader:@"Content-Type"
value:@"multipart/form-data;boundary=---------------------------1842378953296356978857151853"];
NSData *imgData=UIImageJPEGRepresentation(userImage, 0.9);
if(imgData != nil){
[request setFile:imgData withFileName:@"Loveatnight" andContentType:@"image/jpeg" forKey:@"image"];
}
//[request addRequestHeader:@"Content-Type"
// value:@"multipart/form-data;boundary=---------------------------1842378953296356978857151853"];
if(videoData != nil){
[request setFile:videoData withFileName:@"Loveishard" andContentType:@"image/jpeg" forKey:@"uploadfile"];
}// error is come on that line
[request setTimeOutSeconds:500];
//NSLog(@"%@",request);
[networkQueue addOperation:request];
[networkQueue go];
由OP添加,
[request setFile:videoData withFileName:@"Loveishard"
andContentType:@"video/quicktime"
forKey:@"uploadfile"];
我使用它是因为我的视频格式是mov ,但它再次出错
I want to post one image to my webservice and one video too , but problem is that when it go to video part it give me Excess-bad Error
NSString *url = [NSString stringWithFormat:@"http://example.com/add_videoxml.php"];
networkQueue = [[ASINetworkQueue alloc] init];
[networkQueue cancelAllOperations];
[networkQueue setShowAccurateProgress:YES];
//[networkQueue setUploadProgressDelegate:progressBar];
[networkQueue setDelegate:self];
[networkQueue setRequestDidFinishSelector:@selector(requestFinished:)];
[networkQueue setRequestDidFailSelector: @selector(requestFailed:)];
request= [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:url]] ;
[request setPostValue:@"284" forKey:@"id"];
[request setPostValue:@"show" forKey:@"show"];
[request addRequestHeader:@"Content-Type"
value:@"multipart/form-data;boundary=---------------------------1842378953296356978857151853"];
NSData *imgData=UIImageJPEGRepresentation(userImage, 0.9);
if(imgData != nil){
[request setFile:imgData withFileName:@"Loveatnight" andContentType:@"image/jpeg" forKey:@"image"];
}
//[request addRequestHeader:@"Content-Type"
// value:@"multipart/form-data;boundary=---------------------------1842378953296356978857151853"];
if(videoData != nil){
[request setFile:videoData withFileName:@"Loveishard" andContentType:@"image/jpeg" forKey:@"uploadfile"];
}// error is come on that line
[request setTimeOutSeconds:500];
//NSLog(@"%@",request);
[networkQueue addOperation:request];
[networkQueue go];
Added by the OP
[request setFile:videoData withFileName:@"Loveishard"
andContentType:@"video/quicktime"
forKey:@"uploadfile"];
i use this becuase my video formate is mov , but it again give error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
videoData
在哪里声明?我在您的代码中没有看到任何对它的引用。另外,为什么要提供
image/jpeg
作为视频的内容类型?我认为你的意思一定是video/mp4
(或者可能是video/mpeg
或video/quicktime
,具体取决于你从哪里获取视频)。Where is
videoData
declared? I don't see any reference to it in your code.Also, why are you providing
image/jpeg
as the content type for a video? I think you must meanvideo/mp4
(or possiblyvideo/mpeg
orvideo/quicktime
, depending on where you're getting the video from).首先,您没有正确设置内容类型。您应该使用适合您的视频文件的 contentType,而不是使用 andContentType:@"image/jpeg"。要查看多媒体文件的不同 MIME 类型,请查看:http://www.w3schools。 com/media/media_mimeref.asp。
并使用例如(如果您有 .avi 文件):
第二:上传二进制数据或文件时,数据会自动以“multipart/form-data”格式发布,您的情况是什么,所以不必担心设置标题。
First of all, you are not setting the content type correctly. Instead of using andContentType:@"image/jpeg" you should use a contentType that fits to your video file. To see the different mime types for multimedia files, take a look at: http://www.w3schools.com/media/media_mimeref.asp.
And use for example (if you have a .avi file):
SECOND: Data is posted in 'multipart/form-data' format AUTOMATICALLY when uploading binary data or files, what is your case, so don't worry about setting the header.