peterchen149 2015-06-09 02:23 采纳率: 0%
浏览 1825

用nsurlsessionuploadtask上传图片失败,求教

     NSString *uploadPicURLStr = @"/jf/platform/upload/appUpload";
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",BASEURL,uploadPicURLStr];
    NSLog(@"urlstr:%@",urlStr);
    NSURL *url = [NSURL URLWithString:urlStr];
//    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request addValue:@"multipart/form-data" forHTTPHeaderField:@"Content-type"];

    [request addValue:@"text/html" forHTTPHeaderField:@"Accept"];
    [request setHTTPMethod:@"POST"];
    [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
    [request setTimeoutInterval:30];
    NSLog(@"request:%@",request);

    NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];
//    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionUploadTask *uploadTask   = [session uploadTaskWithRequest:request fromData:imgData completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//        NSLog(@"data:%@",data);
        NSString *string = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"data str:%@",string);
        NSLog(@"success:%@",response);
        NSLog(@"error:%@",error);
    }];
    [uploadTask resume];

imgdata是传过来的nsdata图片数据,
报了个:Separation boundary was not specified 错。
请问怎么破?
更新:打印了上传的数据,

 -(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend{
    NSLog(@"already sent:%lld",bytesSent);
    NSLog(@"totoal to send:%lld",totalBytesSent);
    NSLog(@"expected send:%lld",totalBytesExpectedToSend);
}

输出结果如下:
2015-06-09 10:42:29.013 Purchaser[1492:52094] already sent:32768
2015-06-09 10:42:29.013 Purchaser[1492:52094] totoal to send:32768
2015-06-09 10:42:29.013 Purchaser[1492:52094] expected send:113761
2015-06-09 10:42:29.013 Purchaser[1492:52097] already sent:32768
2015-06-09 10:42:29.014 Purchaser[1492:52097] totoal to send:65536
2015-06-09 10:42:29.014 Purchaser[1492:52097] expected send:113761
2015-06-09 10:42:29.014 Purchaser[1492:52094] already sent:32768
2015-06-09 10:42:29.014 Purchaser[1492:52094] totoal to send:98304
2015-06-09 10:42:29.015 Purchaser[1492:52094] expected send:113761
2015-06-09 10:42:29.015 Purchaser[1492:52097] already sent:15457
2015-06-09 10:42:29.015 Purchaser[1492:52097] totoal to send:113761
2015-06-09 10:42:29.015 Purchaser[1492:52097] expected send:113761

看起来是传出去了,但是服务器那边没收到,头疼。。。。

  • 写回答

1条回答

  • 仟微科技 业界专家认证 2015-06-10 00:14
    关注

    DavLockDB "/usr/var/DavLock"

    Alias /uploads "/usr/uploads"


    Dav On

    Order Allow,Deny
    Allow from all
    
    #用户的授权类型
    AuthType Basic
    AuthName DAV-upload
    
    # You can use the htdigest program to create the password database:
    #   htdigest -c "/usr/user.passwd" DAV-upload admin
    # 用户密码文件
    AuthUserFile "/usr/webdav.passwd"
    AuthDigestProvider file
    
    # Allow universal read-access, but writes are restricted
    <LimitExcept GET OPTIONS>
        require user admin
    </LimitExcept>
    

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮