You need to add Content-Disposition: attachment to the header of a file when uploading it to storage. This will tell the browser to download, not display the image in a browser.
Example Firebase v9:
import { getStorage, ref, uploadBytes, getDownloadURL } from 'firebase/storage'
async function onChangeFileUpload(file) {
const imageRef = ref(getStorage(), `images/${file.value.files[0].name}`)
const metadata = {
contentDisposition: 'attachment'
}
const result = await uploadBytes(imageRef, file.value.files[0], metadata)
const doUrl = await getDownloadURL(result.ref)
// Save downloadURL link in database.
}
Another way, if you want user to download any file by one click, you need to use <a href="" download>.
If you want to download the image manually, Just download it, and save it as you_filename.jpg. When you add the extension, your file explorer is smart enough to decode the image, and you can see the thumbnail.
Using Python Requests
As the weblink have the media access token, you can download the image using simple get request. Make sure you write the file name with the file extension donwloadedimage.jpg as given below
import requests
def download_image(url):
r = requests.get(url=url)
path="downloadedimage.jpg"
if r.status_code == 200:
print("File Downloaded")
with open(path, 'wb') as f:
f.write(r.content)
print("File Saved")
else:
print("Something went wrong")
download_url="https://firebasestorage.googleapis.com/v0/b/welook-siwe.appspot.com/o/moments%2F58810%2Ffe2c6769-af55-4fb3-a73f-4bac3bb2dbc3?alt=media&token=a123aaa3-7e77-4f1a-88cb-9f5169fd5b6e"
download_image(download_url)
While Uploading
Make sure you upload the image with the extension. If you upload without extension , Firebase will consider the object-type as not as image/jpg but as application/octet-stream
When File Extension is not provided in Firebase
If you did that, reupload the image with right extension by renaming the file with right extension (jpg/jpeg/png).
2
Answers
You need to add
Content-Disposition: attachment
to the header of a file when uploading it to storage. This will tell the browser to download, not display the image in a browser.Example Firebase v9:
Another way, if you want user to download any file by one click, you need to use
<a href="" download>
.Downloading file via link:
By the way, your link is lack of file extension
.jpg
.Changing the file name while saving
If you want to download the
image manually
, Just download it, and save it asyou_filename.jpg
. When you add the extension, your file explorer is smart enough to decode the image, and you can see the thumbnail.Using Python Requests
As the weblink have the media access token, you can download the image using simple
get
request. Make sure you write the file name with the file extensiondonwloadedimage.jpg
as given belowWhile Uploading
Make sure you upload the image with the
extension
. If you upload without extension , Firebase will consider theobject-type
as not asimage/jpg
but asapplication/octet-stream
When File Extension is not provided in Firebase
If you did that, reupload the image with right extension by renaming the file with right extension
(jpg/jpeg/png)
.