Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from google.cloud import storage
|
3 |
+
|
4 |
+
def upload_file_to_gcs(file_url, bucket_name, object_name):
|
5 |
+
# Download the file from the URL
|
6 |
+
response = requests.get(file_url)
|
7 |
+
file_content = response.content
|
8 |
+
|
9 |
+
# Initialize the Google Cloud Storage client
|
10 |
+
storage_client = storage.Client()
|
11 |
+
|
12 |
+
# Get the bucket
|
13 |
+
bucket = storage_client.bucket(bucket_name)
|
14 |
+
|
15 |
+
# Create a new blob and upload the file content
|
16 |
+
blob = bucket.blob(object_name)
|
17 |
+
blob.upload_from_string(file_content)
|
18 |
+
|
19 |
+
print(f"File uploaded to {bucket_name}/{object_name}")
|
20 |
+
|
21 |
+
# Replace 'your-bucket-name' and 'your-file-name.ext' with your actual bucket name and desired object name
|
22 |
+
bucket_name = 'your-bucket-name'
|
23 |
+
file_url = 'https://example.com/your-file.ext'
|
24 |
+
object_name = 'your-file-name.ext'
|
25 |
+
|
26 |
+
upload_file_to_gcs(file_url, bucket_name, object_name)
|