我正在尝试将用户信息上传到firebase服务器。我已按照谷歌提供的guide尝试这样做,但出于不明原因我收到错误。
以下是我执行上传任务的方法
NSMutableDictionary *userdata = [[NSMutableDictionary alloc] init];
[userdata setObject:name forKey:@"name"];
[userdata setObject:email forKey:@"email"];
[userdata setObject:username forKey:@"username"];
[userdata setObject:handphoneNumber forKey:@"HPNO"];
[[FIRAuth auth] createUserWithEmail:email password:password completion:^(FIRUser * _Nullable user, NSError * _Nullable error) {
if (user) {
NSString *storageUrl = [FIRApp defaultApp].options.storageBucket;
self.storageRef = [[FIRStorage storage] referenceForURL:[NSString stringWithFormat:@"gs://%@", storageUrl]];
NSString *usrstring = [NSString stringWithFormat:@"%@",userdata];
NSData *data = [NSData dataWithContentsOfFile:usrstring];
FIRStorageReference *userRef = [self.storageRef child:usrstring];
FIRStorageUploadTask *uploadTask = [userRef putData:data
metadata:nil
completion:^(FIRStorageMetadata * metadata, NSError * error) {
if (error) {
NSLog(@"ERROR -- %@",error);
}
}];
}
}];
在执行任务的运行时,我在控制台中面对此
Cannot get file size: (null)
(null)
2017-02-15 01:38:09.772 E-Learning[2280:92867] ERROR -- Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={object={
HPNO = 123123;
email = "test@gmail.com";
name = test;
username = test;
}, bucket=firebase-testrun8519.appspot.com, ResponseBody={
"error": {
"code": 500,
"message": "An internal error has occurred. Could not access bucket firebase-testrun8519.appspot.com"
}
}, data=<7b0a2020 22657272 6f72223a 207b0a20 20202022 636f6465 223a2035 30302c0a 20202020 226d6573 73616765 223a2022 416e2069 6e746572 6e616c20 6572726f 72206861 73206f63 63757272 65642e20 20436f75 6c64206e 6f742061 63636573 73206275 636b6574 20666972 65626173 652d656c 6561726e 696e6773 672e6170 7073706f 742e636f 6d220a20 207d0a7d>, NSLocalizedDescription=An unknown error occurred, please check the server response., ResponseErrorDomain=com.google.HTTPStatus, ResponseErrorCode=500}
任何帮助都将非常感谢并提前感谢
答案 0 :(得分:0)
我会清理要更改的代码:
NSString *storageUrl = [FIRApp defaultApp].options.storageBucket;
self.storageRef = [[FIRStorage storage] referenceForURL:[NSString stringWithFormat:@"gs://%@", storageUrl]];
成为:
self.storageRef = [[FIRStorage storage] reference];
此外,dataWithContentsOfFile:
采用一个字符串表示磁盘上文件的路径,而不是您要上传的字符串。相反,您想使用NSString dataUsingEncoding:
(我建议使用NSUTF8StringEncoding
)。有关详情,请参阅the docs。