• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iphone - 暂停/恢复从 iphone 上传到服务器的文件

[复制链接]
菜鸟教程小白 发表于 2022-12-12 09:39:51 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在通过 HTTP 发布将视频上传到服务器。

如何通过单击按钮来暂停和恢复此上传过程

我正在使用以下代码

  NSString *urlString =@"http://sampleurl.com/upload_video";

  NSMutableURLRequest *request= [[[NSMutableURLRequest alloc] init] autorelease];
 [request setURL:[NSURL URLWithString:urlString]];
 [request setHTTPMethod"OST"];


  [postbody appendData:[[NSString stringWithFormat"Content-Disposition: form-data; name=\"user_id\"\r\n\r\n%@", appDelegate.userid] dataUsingEncoding:NSUTF8StringEncoding]];
 [postbody appendData:[[NSString stringWithFormat"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];


 [postbody appendData:[[NSString stringWithFormat"Content-Disposition: form-data; name=\"video\"; filename=\"%@\"\r\n", @"a.mov"] dataUsingEncoding:NSUTF8StringEncoding]];
 [postbody appendData:[[NSString stringWithString"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
 [postbody appendData:[NSData dataWithData:file]];
 [postbody appendData:[[NSString stringWithFormat"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
 [request setHTTPBody:postbody];

 conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  if (conn) {
   webData = [[NSMutableData data] retain];
   }    



Best Answer-推荐答案


有一个可以使用的连接委托(delegate)方法

(void)connectionNSURLConnection *)connection   didSendBodyDataNSInteger)bytesWritten  totalBytesWrittenNSInteger)totalBytesWritten   totalBytesExpectedToWrite (NSInteger)totalBytesExpectedToWrite;

您可以存储暂停连接时发送的总字节数,然后将剩余的数据字节发送到网络服务。但请记住,您的网络服务也应该能够收集数据,然后从中创建图像。

希望我能帮上忙。

关于iphone - 暂停/恢复从 iphone 上传到服务器的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15401941/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap