Downloading Firebase Storage Files Device Issue
I assume that the issue here is that the tmp
and Documents
directories don't actually live at /tmp
and /Documents
(for instance, it appears as though /Documents
is actually /User/Documents
, which is actually /private/var/mobile/Documents
, see: https://www.theiphonewiki.com/wiki/)
You'll want to make sure you're creating your File URLs based off where the system thinks those directories are, rather than a string:
NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory()];
NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"my_file"] URLByAppendingPathExtension:@"txt"];
Or similar for NSDocumentDirectory
. As for why that works on the simulator: I assume this is because sandboxing on the simulator doesn't work the same way as a real device, and that /tmp
is apparently a valid location you can write to (though likely not the one you want to be writing two, as evidenced by iOS throwing a hissy fit when you try to do it on a real device).
Error when downloading from Firebase storage
This is not a storage error, it's actually an issue with the file you're attempting to write to.
Looks like URLByAppengingString
should be fileURLWithPath
to get a file system URL (per NSFileManager creating directory error 518 NSFileWriteUnsupportedSchemeError).
Long term we need to fish this out and serve it as a "see relevant error" rather than "read network response."
Firebase Storage Resource Not Downloading in Flutter App
Your code defines a function called download
, but you don't actually invoke that function anywhere.
To execute the code in the download
function you defined, add download()
right before the closing }
of onPressed
:
ElevatedButton(
onPressed: () {
Future<void> download() async {
...
if (e.code == 'permission-denied') {
print(
'User does not have permission to upload to this reference.');
}
});
}
download(); // br> },
child: Text("Track Title")),
Firebase Storage download to local file error
The problem is that at the moment when you write this line:
let downloadTask = imageRef.write(toFile: localURL) { (URL, error) -> Void in
etc.
you don't yet have permission to write to that (localURL
) location. To get the permission you need to write the following code before trying to write anything to localURL
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let localURL = documentsURL.appendingPathComponent("filename")
By doing it you will write the file into the following path on your device (if you are testing on the real device):
file:///var/mobile/Containers/Data/Application/XXXXXXXetc.etc./Documents/filename
If you are testing on the simulator, the path will obviously be somewhere on the computer.
Problem in download Imageuri in Firebase Storage Android
in uploadToFirebase
method inside
reference.getDownloadUrl().addOnSuccessListener(uri -> {.....
instead of mImageUri.toString()
put uri.toString()
as per bellow.So you will get actual url and will solve your problem.
private void uploadToFirebase(Uri mImageUri) {
if (mImageUri != null) {
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setTitle("Uploading...");
progressDialog.show();
StorageReference reference = storageReference.child(System.currentTimeMillis()
+ "." + getFileExtension(mImageUri));
reference.putFile(mImageUri)
.addOnSuccessListener(taskSnapshot -> {
progressDialog.dismiss();
Toast.makeText(getActivity(), "Saved Succesfully", Toast.LENGTH_SHORT).show();
reference.getDownloadUrl()
.addOnSuccessListener(uri -> {
Upload upload = new Upload(uri.toString());
String uploadId = databaseReference.push().getKey();
databaseReference.child(uploadId).setValue(upload);
});
})
.addOnProgressListener(snapshot -> {
double progress = (100.0 * snapshot.getBytesTransferred() / snapshot
.getTotalByteCount());
progressDialog.setMessage("Uploaded " + (int) progress + "%");
})
.addOnFailureListener(e -> {
progressDialog.dismiss();
Toast.makeText(getActivity(), "Error Ocurred" + e.getMessage(), Toast.LENGTH_SHORT).show();
});
}
}
Firebase Storage: Fail to download file even with public access
Try change :
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write:if true
}
}
}
Related Topics
After Getting Image from Uiimagepickercontroller, Uiimageview Rotates Image for iPhone 5
"Unexpectedly Found Nil While Unwrapping an Optional Value" When Retriveing Pffile from Parse.Com
Use of or Operator on Cloudkit Predicate
Get Element from Array of Dictionaries According to Key
Stanford Calculator App Keeps Crashing
Cannot Read Property 'Keycode' 'Character' Assertion Failure When Detect Modifier Key + Numeric Key
Access Enum Associated Value as Optional
Getting Wrong Date from Dateformat
Change Document in Open Window in MACos App
Differencebetween Sequencetype and Collectiontype in Swift
How to Filter Nsarray in Swift
Swiftui Mysterious Spacing Between Large Text and Textfield in VStack
Can Openssl Be Bundled for Wget Wrapper App to Reference in Xcode Project
How to Add Characters into Dateformatter
Swift Issue in Passing Variable Number of Parameters
How to Make a Uiview Grow in Uiview.Animate() with an Accurate Corner Radius