storageRef.downloadURL isn't executing code inside












1















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)
}
}









share|improve this question























  • 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


















1















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)
}
}









share|improve this question























  • 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
















1












1








1








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)
}
}









share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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





















  • 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














2 Answers
2






active

oldest

votes


















0














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
}
}
}





share|improve this answer
























  • 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



















0














Your API call is asynchronic so that why you need instead of print actually use completion block to return the result (error or value).






share|improve this answer
























  • How would I do this? Sorry I am new to this

    – Cristian
    Nov 21 '18 at 1:19













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
});


}
});














draft saved

draft discarded


















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









0














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
}
}
}





share|improve this answer
























  • 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
















0














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
}
}
}





share|improve this answer
























  • 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














0












0








0







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
}
}
}





share|improve this answer













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
}
}
}






share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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













0














Your API call is asynchronic so that why you need instead of print actually use completion block to return the result (error or value).






share|improve this answer
























  • How would I do this? Sorry I am new to this

    – Cristian
    Nov 21 '18 at 1:19


















0














Your API call is asynchronic so that why you need instead of print actually use completion block to return the result (error or value).






share|improve this answer
























  • How would I do this? Sorry I am new to this

    – Cristian
    Nov 21 '18 at 1:19
















0












0








0







Your API call is asynchronic so that why you need instead of print actually use completion block to return the result (error or value).






share|improve this answer













Your API call is asynchronic so that why you need instead of print actually use completion block to return the result (error or value).







share|improve this answer












share|improve this answer



share|improve this answer










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





















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith