File size: 922 Bytes
397d469
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8fc7ce7
 
397d469
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import requests
from google.cloud import storage

def upload_file_to_gcs(file_url, bucket_name, object_name):
    # Download the file from the URL
    response = requests.get(file_url)
    file_content = response.content

    # Initialize the Google Cloud Storage client
    storage_client = storage.Client()

    # Get the bucket
    bucket = storage_client.bucket(bucket_name)

    # Create a new blob and upload the file content
    blob = bucket.blob(object_name)
    blob.upload_from_string(file_content)

    print(f"File uploaded to {bucket_name}/{object_name}")

# Replace 'your-bucket-name' and 'your-file-name.ext' with your actual bucket name and desired object name
bucket_name = 'your-bucket-name'
file_url = 'https://dkstatics-public.digikala.com/digikala-products/26c6255b595c4aac4c30f7fa6644c1a726b70972_1694005299.jpg'
object_name = '1694005299.jpg'

upload_file_to_gcs(file_url, bucket_name, object_name)