Вы можете использовать эту функцию PHP gmp_nextprime()
Можете ли вы попробовать
// Create a reference to the file you want to download
let starsRef = storageRef.child("images/stars.jpg")
// Fetch the download URL
starsRef.downloadURL { url, error in
if let error = error {
// Handle any errors
} else {
// Get the download URL for 'images/stars.jpg'
}
}
Это моя версия для Swift 3 / Swift 4.
Объяснение того, что происходит в коде.
Это по существу тот же ответ, что и Sh_Khan's. Но в его примере пользователь уже знает путь к ведро. В моем примере мы получаем путь от задачи загрузки. Именно это и привело меня к этому вопросу, а также то, что, как мне кажется, искал, когда он искал замену metadata.downloadURL()
.
class StorageManagager {
private let storageReference: StorageReference
init() {
// first we create a reference to our storage
// replace the URL with your firebase URL
self.storageReference = Storage.storage().reference(forURL: "gs://MYAPP.appspot.com")
}
// MARK: - UPLOAD DATA
open func uploadData(_ data: Data, named filename: String, completion: @escaping (URL? , Error?) -> Void) {
let reference = self.storageReference.child(filename)
let metadata = StorageMetadata()
metadata.contentType = "ourType" // in my example this was "PDF"
// we create an upload task using our reference and upload the
// data using the metadata object
let uploadTask = reference.putData(data, metadata: metadata) { metadata, error in
// first we check if the error is nil
if let error = error {
completion(nil, error)
return
}
// then we check if the metadata and path exists
// if the error was nil, we expect the metadata and path to exist
// therefore if not, we return an error
guard let metadata = metadata, let path = metadata.path else {
completion(nil, NSError(domain: "core", code: 0, userInfo: [NSLocalizedDescriptionKey: "Unexpected error. Path is nil."]))
return
}
// now we get the download url using the path
// and the basic reference object (without child paths)
self.getDownloadURL(from: path, completion: completion)
}
// further we are able to use the uploadTask for example to
// to get the progress
}
// MARK: - GET DOWNLOAD URL
private func getDownloadURL(from path: String, completion: @escaping (URL?, Error?) -> Void) {
self.storageReference.child(path).downloadURL(completion: completion)
}
}
.downloadURL
действительно нужно называть starsRef
вместо storageRef
, как сказано в документации, что имеет для меня гораздо больше смысла
– vbuzze
17 May 2018 в 22:16
Этот вопрос появляется для всех поисков языка. Следовательно, для Котлина решение является чем-то вроде ниже:
val photoRef = FirebaseStorage.getInstance()
.reference.child("images/stars.jpg")
// Code ommited - Do some saving - putFile
photoRef.downloadUrl.addOnSuccessListener({ uri ->
product.imageUrl = uri.toString()
})
Однако это нехорошее решение. Вам лучше сохранить путь, а затем перестроить полный URL по требованию. Например:
photoRef.downloadUrl.addOnSuccessListener({ uri ->
val imagePath = uri.toString()
// Save to database
})
Теперь вы можете использовать его позже и только по запросу:
FirebaseStorage.getInstance().reference.child(product.imageUrl).downloadUrl
.addOnSuccessListener { uri ->
String imageUrl = uri.toString()
// Load in images
}
storageRef.downloadURL
вместоstarsRef.downloadURL
, но для меня это не имеет никакого смысла, это должно быть starsRef.? – vbuzze 10 May 2018 в 21:03starsRef
илиstorageRef
?starsRef
имеет смысл, но в документации говорится об обратном – vbuzze 10 May 2018 в 22:49.downloadURL
действительно нужно называтьstarsRef
вместоstorageRef
, как сказано в документации, что имеет для меня гораздо больше смысла – vbuzze 17 May 2018 в 22:18