Firebase上传文件获取可选字符串的文件名 [英] Firebase uploading file getting optional string in filename

查看:121
本文介绍了Firebase上传文件获取可选字符串的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上传图片时,我正在实施Firebase友好的聊天示例。获得可选字符串的响应。什么是错过的?

 可选(FIRStorageMetadata 0x7fc84aced790:{
bucket =abc.appspot.com;
contentEncoding = identity;
contentType =image / jpeg;
downloadTokens =abctoken;
generation = 1231231;
metageneration = 1;
name = 可选(\S5CKnKUykANdxSvZ3wujpMXHTvg1\)/ 494509700277 / asset.JPG;
timeCreated =2016-09-02T11:49:00.114Z;
updated =2016-09-02T11 :49:00.114Z;
})

我的代码:

  let filePath =(FIRAuth.auth()!. currentUser!.uid)/(IntDNSDate.time IntervalSinceReferen ceDate 1000))/(referenceUrl.lastPathComponent!)

在样本中使用可选值(?)所以我把它转换(!)

解决方案

在swift中,你必须强制展开值来避免这个(但是确保它不是零)。



\(optionalVa )



或以标准方式解开它

  if let value = optionalValue {
someFIRMethod(\(value))
}


I was implementing Firebase friendly chat sample while uploading image. Getting response with optional string. what is missed?

Optional(FIRStorageMetadata 0x7fc84aced790: {
    bucket = "abc.appspot.com";
    contentEncoding = identity;
    contentType = "image/jpeg";
    downloadTokens = "abctoken";
    generation = 1231231;
    metageneration = 1;
    name = "Optional(\"S5CKnKUykANdxSvZ3wujpMXHTvg1\")/494509700277/asset.JPG";
    timeCreated = "2016-09-02T11:49:00.114Z";
    updated = "2016-09-02T11:49:00.114Z";
})

My code:

 let filePath = "(FIRAuth.auth()!.currentUser!.uid)/(Int(NSDate.time‌​IntervalSinceReferen‌​ceDate() * 1000))/(referenceUrl.lastPathComponent!)"

was written with optional value (?) in sample so i convert it (!)

解决方案

In swift you must force unwrap value to avoid this (but make sure, it's not nil).

"\(optionalValue!)"

Or unwrap it in standard way

if let value = optionalValue {
    someFIRMethod("\(value)")
}

这篇关于Firebase上传文件获取可选字符串的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆