我試圖從新的Firebase存儲將圖像下載到本地文件。爲此,我使用Firebase提供的示例here。這是我的代碼:未從Firebase存儲下載的圖像
func getTumbnails(imageName: String) {
// Create a reference to the file you want to download
let tumbnailRef = storageRef.child("tumbs/\(imageName)")
// Create local filesystem URL
let localURL: NSURL! = NSURL(string: "file:///local/tumbnails/\(imageName)")
// Download to the local filesystem
let downloadTask = tumbnailRef.writeToFile(localURL) { (URL, error) -> Void in
if (error != nil) {
print(error)
} else {
let data = NSData(contentsOfURL: URL!)
self.data = data!
print(data)
}
}
}
但是當我調用該函數getTumbnails("image")
我收到以下錯誤打印到控制檯:發生
可選(錯誤域= FIRStorageErrorDomain代碼= -13000「未知錯誤, 「UserInfo = {object = tumbs/Sunset.png,bucket = ********。appspot.com,NSLocalizedDescription =發生未知錯誤,請檢查服務器響應。,ResponseErrorDomain = NSCocoaErrorDomain ,NSFilePath =/local/tumbnails,NSUnderlyingError = 0x137f629c0 {Error Domain = NSPOSIXErrorDomain Code = 1「Operation not permitted」},ResponseErrorCode = 513})
我發現this問題在這裏stackoverflow,但這是一個不同的錯誤(響應代碼518,而我有513),因爲我直接使用示例代碼,這應該只是工作。
有人可以幫我嗎?
謝謝!但是,這適用於模擬器,但不適用於實際設備。 –
模擬器上的應用程序沙盒可能與設備上的運行方式不同 - 您在設備上遇到了哪些問題?這也可能是你在設備上擁有不同的權限,並且不能寫入'/ Documents'(你可能需要寫入你的用戶目錄或只是寫入/ tmp) –
我已經試圖寫入'/ tmp'沒有成功:( –