Oxylabs Documentation
English
Search
⌃K

Download Images

It is possible to download images via Proxy Endpoint. If you do that through Proxy Endpoint, you can save the output to an image extension.
For example:
curl -k -x realtime.oxylabs.io:60000 -U user:pass1 "https://example.com/image.jpg" >> image.jpg
If you are using the Push-Pull or Realtime methods, you will need to add the content_encoding parameter with a value of base64.
Once you receive the results, you need to decode encoded data from content into bytes and save it as an image file.
Here's an example written in Python:
import base64
import json
import requests
# Your credentials.
USERNAME = ''
PASSWORD = ''
# Image URL which will be saved to file.
URL_IMAGE = 'https://example.com/image.jpg'
# Realtime URL.
API_URL = f'http://{USERNAME}:{PASSWORD}@realtime.oxylabs.io/v1/queries'
def dump_to_file(filename: str, data: bytes):
with open(filename, 'wb') as file:
file.write(data)
def main():
parameters = {
'source': 'universal_ecommerce',
'url': URL_IMAGE,
'content_encoding': 'base64',
}
response = requests.post(API_URL, json=parameters)
if response.ok:
data = json.loads(response.text)
content_base64 = data['results'][0]['content']
# Decode base64 encoded data into bytes.
content = base64.b64decode(content_base64)
dump_to_file('out.jpg', content)
if __name__ == '__main__':
main()