I have a URL like this who corresponds to an image shown in a website:
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
I need to download that image but i can't because it just downloads me this kind of file when i click on the URL:
Is there any way to download that image using only the URL?
Changing the file name while saving
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).
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>.
Downloading file via link:
<a href="https://example.com/link/to/your/file.jpg" download>Download File>></a>
By the way, your link is lack of file extension .jpg.
Related
hope you guys can help me with this as I'm kinda new to scrapy/web scraping in general and not really sure on how to proceed forward with this problem.
Essentially, I have 2 spiders:
audio_file_downloader_spider, This spider is going to:
check whether a particular webpage passed to it contains an audio file (.mp3/.wav, etc.)
Suppose that an audio file URL is found on the webpage, download the audio file to the local machine.
Suppose that there is NO audio file URL found on the webpage, please tell audio_recorder_spider to scrape the webpage
audio_recorder_spider, is going to use selenium chromedriver and it will:
Press the audio player play button on the webpage
Record the playback stream to an mp3 file (this is definitely doable)
Now... the problem I'm currently facing is..., how do we do something like this with scrapy?
Currently, I have both spiders ready and I can run the audio_file_downloader_spider with this command from the terminal (I'm using macOS):
scrapy crawl audio_file_downloader_spider \
-a url="<some_webpage_url>"
Now, I need to somehow tell scrapy to execute audio_recorder_spider on the same webpage url IF and ONLY IF there is no audio file URL detected on the webpage so that audio_recorder_spider can record the audio playback on the webpage.
Now I'm not too familiar with scrapy just yet but I did read the their item pipeline documentation. One of the examples they gave in their documentation shows a code which will automatically get a screenshot off of a URL using Splash and save that screenshot as a PNG file with a custom name. The code can be seen below:
import hashlib
from urllib.parse import quote
import scrapy
from itemadapter import ItemAdapter
from scrapy.utils.defer import maybe_deferred_to_future
class ScreenshotPipeline:
"""Pipeline that uses Splash to render screenshot of
every Scrapy item."""
SPLASH_URL = "http://localhost:8050/render.png?url={}"
async def process_item(self, item, spider):
adapter = ItemAdapter(item)
encoded_item_url = quote(adapter["url"])
screenshot_url = self.SPLASH_URL.format(encoded_item_url)
request = scrapy.Request(screenshot_url)
response = await maybe_deferred_to_future(spider.crawler.engine.download(request, spider))
if response.status != 200:
# Error happened, return item.
return item
# Save screenshot to file, filename will be hash of url.
url = adapter["url"]
url_hash = hashlib.md5(url.encode("utf8")).hexdigest()
filename = f"{url_hash}.png"
with open(filename, "wb") as f:
f.write(response.body)
# Store filename in item.
adapter["screenshot_filename"] = filename
return item
So this got me thinking, would it be possible to do the same thing but instead of using Splash and taking a screenshot of the webpage, I want to use Selenium and record the audio playback off of the URL.
Any help would be greatly appreciated, thanks in advance!
I have an App that display nightclub description and image. Each club have about 4 related image.
In Firebase Storage i have created directory for each club and then stored their image inside.
so what i want to do is getting all the image from a club directory so i can display all the image in my app
i think a way of achieving this would be to get the DownloadUrl of each image.
i've tried this :
final StorageReference firebaseStorageRef = FirebaseStorage.instance.ref()
.child('profilePics/$clubID/SomeImage.jpg').getDownloadURL();
but since i don't know in advance the name of the image stored i can't use this
so any way of doing this ?
Future<void> listExample() async {
firebase_storage.ListResult result =
await firebase_storage.FirebaseStorage.instance.ref().listAll();
result.items.forEach((firebase_storage.Reference ref) {
print('Found file: $ref');
});
result.prefixes.forEach((firebase_storage.Reference ref) {
print('Found directory: $ref');
});
}
this code worked for me i got it from flutter fire website
here is the link to the docs
https://firebase.flutter.dev/docs/storage/usage
If you don't know the full path of an object in Cloud Storage, then you can't do anything with it using the mobile client SDKs. Typically, one gets the download URL at the time it was uploaded to the bucket, then writes that URL to a database so it can be queried for later.
A solution I came up with was, storing a .txt file which contained the name of each file, so first I read the text file, by line-breaking the file apart, and downloading my images in the same folder with the name of the file I got from the text file. This can work, if you can can store the names of all your files in a text file and then upload it!
Flow of the solution:
Store all the names of the files in the Firebase Storage's folder in a .txt file
write a method to get the text file and the break it line-by-line
write a method to get a download url, have this method call each time you get the name of your file from the .txt file.
use the image url as per your wish!
Any suggestions or corrections are welcomed!
https://github.com/FirebaseExtended/flutterfire/pull/232
Need to use package in pubspec.yaml like below :
firebase_storage:
git:
url: git://github.com/danysz/flutterfire.git
ref: master
path: packages/firebase_storage
Dart file
void getFirebaseImageFolder() {
final StorageReference storageRef =
FirebaseStorage.instance.ref().child('Gallery').child('Images');
storageRef.listAll().then((result) {
print("result is $result");
});
Original post by Mahesh Peri
I am new to TXTextControl. I am currently using TXTextControl 24 version.
I need to upload an image from local system (Client system) into the document.
I have written the JS for uploading the file through .
The JS makes a call to backend service which gets the file, Add it to a new RTF file and respond back to JS. The RTF file is then loaded to the Selection.Load of TextControl.
Code: add image to RTF
TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl();
tx.Create();
tx.Images.Add(myImage, tx.InputPosition.Page, new Point(100, 100), TXTextControl.ImageInsertionMode.FixedOnPage);
string sHTML;
tx.Save(out sHTML, TXTextControl.StringStreamType.RichTextFormat);
The server responds back with with message "The Module for displaying image is obsolete. (01-0803)"
How can I add the Image into the TXTextControl Document ?
I thought this would be easy.
I want to create simple files the user can download by clicking a link.
Write what you want into the servers assets/app folder and then generate a simple link
Download> me!
Writing files into Meteor's server side asset folder is easy. And the download link above will always download a file with the name you specified.
You will get a yourNewFile.txt in the client's download folder. But, unfortunately its content will not be what you wrote on the server (new.txt).
Meteor has the strange behavior of downloading its startup html page as the content if the name of your content wasn't originally in the public folder. I think this is bug .... put the above anchor into a default Meteor project and click the link .. don't even create a public folder. You get a downloaded file with the name you asked for...
So, if you put stubs in the public folder (you know the names of the assets you are going to create) then you can create them dynamically.
I don't know the names before hand. Is there any way to get Meteor to 'update' its assets list with the new names I want to use?
I know there are packages that can do this. I'd like to just do it myself as above, really shouldn't be this hard.
The public/ folder intended use is specifically for static assets. Its content is served by the node http server.
If you want to dynamically generate assets on the server, you can rely on iron:router server side routes.
Here is a simple example :
lib/router.js
Router.route("/dynamic-asset/:filename",function(){
var filename = this.params.filename;
this.response.setHeader("Content-Disposition",
"attachment; filename=" + filename);
this.response.end("Hello World !");
},{
name: "dynamic-asset",
where: "server"
});
In server-side route controllers, you get access to this.response which is a standard node HTTP response instance to respond to the client with the correct server generated content. You can query your Mongo collections using the eventual parameters in the URL for example.
client/views/download/download.html
<template name="download">
{{#linkTo route="dynamic-asset" target="_blank" download=""}}
Download {{filename}}
{{/linkTo}}
</template>
client/views/parent/parent.html
<template name="parent">
{{> download filename="new.txt"}}
</template>
The linkTo block helper must be called in a context where the route parameters are accessible as template helpers. It will generate an anchor tag having an href set to Router.path(route, dataContext). It means that if our server-side route URL is /dynamic-asset/:filename, having a data context where filename is accessible and set to "new.txt" will generate this URL : /dynamic-asset/new.txt.
In this example we set the current data context of the download template to {filename: "new.txt"} thanks to the template invocation syntax.
Note that target="_blank" is necessary to avoid being redirected to the dynamic asset URL inside the current tab, and the download HTML attribute must be set to avoid considering the link as something the browser should open inside a new tab. The download attribute value is irrelevant as it's value will be overriden server-side.
Here is the raw Picker (meteorhacks:picker) route and method I used to get this running. I've kept it lean and its just what I got working and probably not the best way to do this ... the synchronous methods (like readFileSync) throw exceptions if things are not right, so they should be wrapped in try-catch blocks and the mkdirp is a npm package loaded through meteorhacks:npm package hence the Meteor.npmRequire. Thanks again to saimeunt for the directions.
Picker.route('/dynamic-asset/:filename', function(params, req, res, next) {
console.log('/dynamic-asset route!');
var fs = Npm.require('fs');
var path = Npm.require('path');
var theDir = path.resolve('./dynamic-asset');
var filename = params.filename;
var fileContent = fs.readFileSync(theDir + '/' + filename, {encoding:'utf8'});
res.end(fileContent);
});
The Meteor method that creates the file is
writeFile: function(fname, content) {
console.log('writeFile', fname);
var fs = Npm.require('fs');
var path = Npm.require('path');
var mkdirp = Meteor.npmRequire('mkdirp');
// verify/make directory
var theDir = path.resolve('./dynamic-asset');
mkdirp(theDir);
fs.writeFileSync(theDir + '/' + fname, content);
return 'aok';
}
and the hyper link I generate on the client if the file gets created looks like this:
Download lane file now
I incorrectly stated in my original question at the top that you could use stubs and write files into the assets folder. Its not so .. you will only get back the stub ... sorry.
I'm deploying a small application with Adobe Air. My application will do batch upload from filepath which stored in a text file.
For example, in a text file name "list.txt", there is a string "C:\myfiles\IMG_0001.JPG". Now I want to upload this image file, keep tracking of upload progress :-<
I want to use FileReference to get the upload progress, but I don't know how to import from file's path. I also wonder how to use FileReference to upload this file without prompting a dialog for user to select file.
Thank you so much :)
Try the following. I have done a file upload without dialog box using following code.
var uploadURLs:URLRequest = new URLRequest("Your upload URL Here");
var params:URLVariables=new URLVariables();
params.title = "Hello";//URL Parameters if there is any
uploadURLs.data = params;
uploadURLs.method=URLRequestMethod.POST;
file = new File("Path to File");
file.addEventListener(ProgressEvent.PROGRESS , updateProgress);
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, doneUpload);
file.addEventListener(IOErrorEvent.IO_ERROR,fileError);
file.upload(uploadURLs);
Hope this helps