storageRef.downloadURL isn't executing code inside
func uploadProfileImage(_ image:UIImage, completion: @escaping ((_ url:URL?)->())) {
guard let uid = Auth.auth().currentUser?.uid else { return }
let storageRef = Storage.storage().reference().child("user/(uid)")
let imageData = image.jpegData(compressionQuality: 0.75)
let metaData = StorageMetadata()
metaData.contentType = "image/jpg"
storageRef.putData(imageData!, metadata: metaData)
//Get url
let imageRef = storageRef
imageRef.downloadURL { url, error in
if let error = error {
print(error.localizedDescription)
}else{
print(url.absoluteString)
}
}
}
The code inside will not execute, it will skip everything and act like there is no code stored. I am unsure how completions work but I would imagine it would either print the error or print the url but it does neither. When I set a breakpoint here it doesn't even bother checking if error = error. Is there something I did wrong or anyone else having the same problem?
imageRef.downloadURL { url, error in
if let error = error {
print(error.localizedDescription)
}else{
print(url.absoluteString)
}
}
swift xcode firebase firebase-realtime-database firebase-storage
add a comment |
func uploadProfileImage(_ image:UIImage, completion: @escaping ((_ url:URL?)->())) {
guard let uid = Auth.auth().currentUser?.uid else { return }
let storageRef = Storage.storage().reference().child("user/(uid)")
let imageData = image.jpegData(compressionQuality: 0.75)
let metaData = StorageMetadata()
metaData.contentType = "image/jpg"
storageRef.putData(imageData!, metadata: metaData)
//Get url
let imageRef = storageRef
imageRef.downloadURL { url, error in
if let error = error {
print(error.localizedDescription)
}else{
print(url.absoluteString)
}
}
}
The code inside will not execute, it will skip everything and act like there is no code stored. I am unsure how completions work but I would imagine it would either print the error or print the url but it does neither. When I set a breakpoint here it doesn't even bother checking if error = error. Is there something I did wrong or anyone else having the same problem?
imageRef.downloadURL { url, error in
if let error = error {
print(error.localizedDescription)
}else{
print(url.absoluteString)
}
}
swift xcode firebase firebase-realtime-database firebase-storage
Your putData:metadata:completion: doesn't have completion block. have a look here firebase.google.com/docs/storage/ios/upload-files
– Govind Kumawat
Nov 20 '18 at 4:49
add a comment |
func uploadProfileImage(_ image:UIImage, completion: @escaping ((_ url:URL?)->())) {
guard let uid = Auth.auth().currentUser?.uid else { return }
let storageRef = Storage.storage().reference().child("user/(uid)")
let imageData = image.jpegData(compressionQuality: 0.75)
let metaData = StorageMetadata()
metaData.contentType = "image/jpg"
storageRef.putData(imageData!, metadata: metaData)
//Get url
let imageRef = storageRef
imageRef.downloadURL { url, error in
if let error = error {
print(error.localizedDescription)
}else{
print(url.absoluteString)
}
}
}
The code inside will not execute, it will skip everything and act like there is no code stored. I am unsure how completions work but I would imagine it would either print the error or print the url but it does neither. When I set a breakpoint here it doesn't even bother checking if error = error. Is there something I did wrong or anyone else having the same problem?
imageRef.downloadURL { url, error in
if let error = error {
print(error.localizedDescription)
}else{
print(url.absoluteString)
}
}
swift xcode firebase firebase-realtime-database firebase-storage
func uploadProfileImage(_ image:UIImage, completion: @escaping ((_ url:URL?)->())) {
guard let uid = Auth.auth().currentUser?.uid else { return }
let storageRef = Storage.storage().reference().child("user/(uid)")
let imageData = image.jpegData(compressionQuality: 0.75)
let metaData = StorageMetadata()
metaData.contentType = "image/jpg"
storageRef.putData(imageData!, metadata: metaData)
//Get url
let imageRef = storageRef
imageRef.downloadURL { url, error in
if let error = error {
print(error.localizedDescription)
}else{
print(url.absoluteString)
}
}
}
The code inside will not execute, it will skip everything and act like there is no code stored. I am unsure how completions work but I would imagine it would either print the error or print the url but it does neither. When I set a breakpoint here it doesn't even bother checking if error = error. Is there something I did wrong or anyone else having the same problem?
imageRef.downloadURL { url, error in
if let error = error {
print(error.localizedDescription)
}else{
print(url.absoluteString)
}
}
swift xcode firebase firebase-realtime-database firebase-storage
swift xcode firebase firebase-realtime-database firebase-storage
asked Nov 20 '18 at 4:37
Cristian Cristian
61
61
Your putData:metadata:completion: doesn't have completion block. have a look here firebase.google.com/docs/storage/ios/upload-files
– Govind Kumawat
Nov 20 '18 at 4:49
add a comment |
Your putData:metadata:completion: doesn't have completion block. have a look here firebase.google.com/docs/storage/ios/upload-files
– Govind Kumawat
Nov 20 '18 at 4:49
Your putData:metadata:completion: doesn't have completion block. have a look here firebase.google.com/docs/storage/ios/upload-files
– Govind Kumawat
Nov 20 '18 at 4:49
Your putData:metadata:completion: doesn't have completion block. have a look here firebase.google.com/docs/storage/ios/upload-files
– Govind Kumawat
Nov 20 '18 at 4:49
add a comment |
2 Answers
2
active
oldest
votes
Your putData:metadata:completion: doesn't have completion block. You can access to download URL after upload so putData should be look like this.
storageRef.putData(imageData!, metadata: metaData) { (metadata, error) in
guard let metadata = metadata else {
// an error occurred!
return
}
// Metadata contains file metadata such as size, content-type.
let size = metadata.size
// You can only access to download URL after upload.
let imageRef = storageRef
imageRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// an error occurred!
return
}
}
}
I tried doing this but it then skips all the code inside of this completion block
– Cristian
Nov 21 '18 at 1:22
@Cristian API call is asynchronous so you need to set a breakpoint inside completion block
– Govind Kumawat
Nov 21 '18 at 4:25
add a comment |
Your API call is asynchronic so that why you need instead of print actually use completion block to return the result (error or value).
How would I do this? Sorry I am new to this
– Cristian
Nov 21 '18 at 1:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386327%2fstorageref-downloadurl-isnt-executing-code-inside%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your putData:metadata:completion: doesn't have completion block. You can access to download URL after upload so putData should be look like this.
storageRef.putData(imageData!, metadata: metaData) { (metadata, error) in
guard let metadata = metadata else {
// an error occurred!
return
}
// Metadata contains file metadata such as size, content-type.
let size = metadata.size
// You can only access to download URL after upload.
let imageRef = storageRef
imageRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// an error occurred!
return
}
}
}
I tried doing this but it then skips all the code inside of this completion block
– Cristian
Nov 21 '18 at 1:22
@Cristian API call is asynchronous so you need to set a breakpoint inside completion block
– Govind Kumawat
Nov 21 '18 at 4:25
add a comment |
Your putData:metadata:completion: doesn't have completion block. You can access to download URL after upload so putData should be look like this.
storageRef.putData(imageData!, metadata: metaData) { (metadata, error) in
guard let metadata = metadata else {
// an error occurred!
return
}
// Metadata contains file metadata such as size, content-type.
let size = metadata.size
// You can only access to download URL after upload.
let imageRef = storageRef
imageRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// an error occurred!
return
}
}
}
I tried doing this but it then skips all the code inside of this completion block
– Cristian
Nov 21 '18 at 1:22
@Cristian API call is asynchronous so you need to set a breakpoint inside completion block
– Govind Kumawat
Nov 21 '18 at 4:25
add a comment |
Your putData:metadata:completion: doesn't have completion block. You can access to download URL after upload so putData should be look like this.
storageRef.putData(imageData!, metadata: metaData) { (metadata, error) in
guard let metadata = metadata else {
// an error occurred!
return
}
// Metadata contains file metadata such as size, content-type.
let size = metadata.size
// You can only access to download URL after upload.
let imageRef = storageRef
imageRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// an error occurred!
return
}
}
}
Your putData:metadata:completion: doesn't have completion block. You can access to download URL after upload so putData should be look like this.
storageRef.putData(imageData!, metadata: metaData) { (metadata, error) in
guard let metadata = metadata else {
// an error occurred!
return
}
// Metadata contains file metadata such as size, content-type.
let size = metadata.size
// You can only access to download URL after upload.
let imageRef = storageRef
imageRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// an error occurred!
return
}
}
}
answered Nov 20 '18 at 5:42


Govind KumawatGovind Kumawat
715310
715310
I tried doing this but it then skips all the code inside of this completion block
– Cristian
Nov 21 '18 at 1:22
@Cristian API call is asynchronous so you need to set a breakpoint inside completion block
– Govind Kumawat
Nov 21 '18 at 4:25
add a comment |
I tried doing this but it then skips all the code inside of this completion block
– Cristian
Nov 21 '18 at 1:22
@Cristian API call is asynchronous so you need to set a breakpoint inside completion block
– Govind Kumawat
Nov 21 '18 at 4:25
I tried doing this but it then skips all the code inside of this completion block
– Cristian
Nov 21 '18 at 1:22
I tried doing this but it then skips all the code inside of this completion block
– Cristian
Nov 21 '18 at 1:22
@Cristian API call is asynchronous so you need to set a breakpoint inside completion block
– Govind Kumawat
Nov 21 '18 at 4:25
@Cristian API call is asynchronous so you need to set a breakpoint inside completion block
– Govind Kumawat
Nov 21 '18 at 4:25
add a comment |
Your API call is asynchronic so that why you need instead of print actually use completion block to return the result (error or value).
How would I do this? Sorry I am new to this
– Cristian
Nov 21 '18 at 1:19
add a comment |
Your API call is asynchronic so that why you need instead of print actually use completion block to return the result (error or value).
How would I do this? Sorry I am new to this
– Cristian
Nov 21 '18 at 1:19
add a comment |
Your API call is asynchronic so that why you need instead of print actually use completion block to return the result (error or value).
Your API call is asynchronic so that why you need instead of print actually use completion block to return the result (error or value).
answered Nov 20 '18 at 6:44


VanyaVanya
3,75842448
3,75842448
How would I do this? Sorry I am new to this
– Cristian
Nov 21 '18 at 1:19
add a comment |
How would I do this? Sorry I am new to this
– Cristian
Nov 21 '18 at 1:19
How would I do this? Sorry I am new to this
– Cristian
Nov 21 '18 at 1:19
How would I do this? Sorry I am new to this
– Cristian
Nov 21 '18 at 1:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386327%2fstorageref-downloadurl-isnt-executing-code-inside%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your putData:metadata:completion: doesn't have completion block. have a look here firebase.google.com/docs/storage/ios/upload-files
– Govind Kumawat
Nov 20 '18 at 4:49