【问题标题】:Error saving images to Parse: "request body stream exhausted"将图像保存到 Parse 时出错:“请求正文流已用尽”
【发布时间】:2016-12-23 14:35:07
【问题描述】:

我在将图像上传到 Parse 时遇到问题。直到昨天一切都很好。我的应用程序还没有上线,我只是在测试,图像大约 25kb,它只是用于用户个人资料图片的单个图像。代码是:

 //Save the image
            NSData *imageData = UIImageJPEGRepresentation(image, 1);
            PFFile *imageFile = [PFFile fileWithName:@"profile.jpg" data:imageData];
            [imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

                if(succeeded){

                    [userBank setObject:imageFile forKey:@"profilePic"];

                    [userBank saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                        if(succeeded){

                           NSLog(@"save done");
                           userBank = [PFUser currentUser];
                           user[@"profilePic"] = imageFile;
                           [userBank saveInBackground];

                        }

                        else{

                            NSLog(@"%@", error);
                            handler(NO,YES,nil);
                        }


                    }];


                }

                else{

                    NSLog(@"image not saved %@",error);
                    handler(NO,YES,nil);
                }

            }];//End save image block

我突然收到此错误:请求主体流已耗尽,NSUnderlyingError=0x17ece150 "请求主体流已耗尽"。有没有人遇到过这种情况,可以给我一些关于这里可能发生的事情的指示?

【问题讨论】:

  • 你在哪一行得到这个错误?
  • 最后的 else,用于将图像保存到 Parse.com 服务器
  • 我认为你做错了,但我不确定,让我检查一下文档
  • 您确定您的互联网连接良好并且解析正常运行吗?老实说,我从未见过此错误,但其他帖子表明这更像是一个滞后问题。 :l
  • 我认为是 Parse。大约 30 分钟后再次开始工作。

标签: ios objective-c parse-platform


【解决方案1】:

试试这个:

NSData *imageData = UIImageJPEGRepresentation(image, 1);
PFFile *imageFile = [PFFile fileWithName:@"profile.jpg" data:imageData];
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
        if (succeeded) {
           userBank = [PFUser currentUser];
            user[@"profilePic"] = imageFile;
            [userBank saveInBackground];
        }
    } else {
         // Handle error
    }        
}];

【讨论】:

  • 嘿,我的代码中实际上有这个,没有把它放在问题中。这是保存图像块失败并返回错误而不是保存用户银行
【解决方案2】:

似乎问题出在我的连接或 Parse 上,尽管我确实尝试过多次重置我的互联网连接,但没有任何区别。无论如何,大约 30 分钟后它又开始工作了。只是发布这个以防其他人有同样的问题。 Parse 似乎并不那么可靠...

【讨论】:

    【解决方案3】:

    试试这个 此错误出现在 IOS 上,但您可以使用不同的方法 比如在你追加文件的地方更改你的代码行

    var fd = new FormData();
    
    fd.append("fileToUpload", document.getElementById('fileToUpload').files[0]);
    

    到下面一行基本上不附加文件控件而是使用base64图像数据

    var reader = new FileReader();

    reader.readAsDataURL(opmlFile.files[0]);
    
    reader.onload = function () {
    
    var base64DataImg = reader.result;            
    
    base64DataImg = base64DataImg.replace('data:'imagetype';base64,', '');      
    formData.append("FileBase64Data", base64DataImg);
    }
    

    问候 阿尼尔

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-23
      • 1970-01-01
      相关资源
      最近更新 更多