它绝对完美地工作-但是-该URL仅仅是不是jpeg的URL -仅仅是文件的URL.点击它会导致您获取jpeg的文件下载.这似乎不可思议-使用所有其他在线存储(AWS等),您只会得到"jpeg的实际URL".这里有解决方案吗?正如BC在下面问到的那样,查看标题:$ cat headers.txtHTTP/1.1 200 OKX-GUploader-UploadID: AEnB2Ur3b5CNUIWWZdwn-666slsPqTjJT3GF83m6sJ-mzx...666Expires: Sat, 29 Jul 2017 23:22:38 GMTDate: Sat, 29 Jul 2017 23:22:38 GMTCache-Control: private, max-age=0Last-Modified: Sat, 29 Jul 2017 18:55:21 GMTETag: "9e4491f86bd78ee62d241d962893f666"x-goog-generation: 1501354521940666x-goog-metageneration: 1x-goog-stored-content-encoding: identityx-goog-stored-content-length: 8992x-goog-meta-firebaseStorageDownloadTokens: cd9e7a4b-6666-666-b6b8-5a700bed2e64Content-Type: application/octet-streamContent-Disposition: inline; filename*=utf-8''0.jpgx-goog-hash: crc32c=z72qJQ==x-goog-hash: md5=nkSR+GvXjuYtJB2WKJP6666==x-goog-storage-class: STANDARDAccept-Ranges: bytesContent-Length: 8992Server: UploadServerAlt-Svc: quic=":443"; ma=2592000; v="39,38,37,36,35"解决方案您的代码正在将原始二进制数据上传到Storage中,而不考虑其内容类型.使用putData时,Storage SDK不会尝试解释该NSData Blob的内容.但是,如果使用putFile,则将推断内容类型 .如果您需要使用putData,请尝试指定一些元数据以及通过putData:metadata:上传的文件.在Firebase控制台中,您可以通过选择文件来检查其上载的内容类型.它也应该在右侧面板中读取image/jpeg.Sending an image to the "Firebase Storage" system ...sr ... a StorageReference (ie, FIRStorageReference)let task = sr.putData(data)task.observe(.success) { [index] snapshot in guard let downloadURL: URL = snapshot.metadata?.downloadURL() else { .. err }However, the end result is URLs, which are like this:https://firebasestorage.googleapis.com/v0/b/someapp.com/o/0.jpg?alt=media&token=113150a1-8152-666-666-fd00dc9e8734It works absolutely perfectly - however - that URL is simply not a URL of a jpeg - it's just a URL of a file. Clicking on it results in you getting a file download of the jpeg.This seems incredible - with all other online storage (AWS etc), you just get "an actual URL of a jpeg".Is there a solution here?As BC asked below, looking at the headers:$ cat headers.txtHTTP/1.1 200 OKX-GUploader-UploadID: AEnB2Ur3b5CNUIWWZdwn-666slsPqTjJT3GF83m6sJ-mzx...666Expires: Sat, 29 Jul 2017 23:22:38 GMTDate: Sat, 29 Jul 2017 23:22:38 GMTCache-Control: private, max-age=0Last-Modified: Sat, 29 Jul 2017 18:55:21 GMTETag: "9e4491f86bd78ee62d241d962893f666"x-goog-generation: 1501354521940666x-goog-metageneration: 1x-goog-stored-content-encoding: identityx-goog-stored-content-length: 8992x-goog-meta-firebaseStorageDownloadTokens: cd9e7a4b-6666-666-b6b8-5a700bed2e64Content-Type: application/octet-streamContent-Disposition: inline; filename*=utf-8''0.jpgx-goog-hash: crc32c=z72qJQ==x-goog-hash: md5=nkSR+GvXjuYtJB2WKJP6666==x-goog-storage-class: STANDARDAccept-Ranges: bytesContent-Length: 8992Server: UploadServerAlt-Svc: quic=":443"; ma=2592000; v="39,38,37,36,35" 解决方案 Your code is uploading raw binary data to Storage without regarding its content type. The Storage SDK is not going to attempt to interpret the contents of that NSData blob when using putData. However, the content type will be inferred if using putFile.If you need to use putData, instead try specifying some metadata along with the upload with putData:metadata:.In the Firebase console, you can check the content type of the file uploaded by selecting it. It should read image/jpeg in the right hand panel as well. 这篇关于"Firebase存储",用于图像-但是,获取实际的URL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-19 02:28