将图像上传到Firebase

Eri*_*rik 2 compression objective-c uiimage ios firebase

我正在尝试将图像上传到Firebase,如下所示:

Firebase *ref = [[Firebase alloc] initWithUrl:@"https://<app-name>.firebaseio.com/posts"];
Firebase *newPost = [ref childByAutoId];

NSDictionary *newPostData = @{
                              @"image" : [self encodeToBase64String:image]
                              };
[newPost updateChildValues:newPostData];
Run Code Online (Sandbox Code Playgroud)

我正在使用此代码对图像进行编码:

- (NSString *)encodeToBase64String:(UIImage *)image {
return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}
Run Code Online (Sandbox Code Playgroud)

但是这不起作用,因为字符串超过了最大大小:

Terminating app due to uncaught exception 'InvalidFirebaseData', reason: '(updateChildValues:) String exceeds max size of 10485760 utf8 bytes:

我该怎么做才能解决这个问题?在使用Firebase时,我没有在iOS开发和图像方面找到任何在线内容.

Fra*_*len 6

如果图像太大,则应存储较小的图像.我自己引用一下:如何通过android将文件保存到Firebase Hosting文件夹位置以获取图像?

Firebase数据库允许您存储JSON数据.虽然二进制数据不是JSON支持的类型,但可以将二进制数据编码为base64,从而将图像存储在(大)字符串中.[但]虽然这是可能的,但不建议除了小图片之外的其他任何东西或作为好奇心看到它可以完成.

您最好的选择通常是将图像存储在第三方图像存储服务上.