Spaces:
Runtime error
Runtime error
adding a google bucket for store 3d models
Browse files- google_buckets.py +38 -0
google_buckets.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from google.cloud import storage
|
2 |
+
|
3 |
+
# Initialize Google Cloud Storage client
|
4 |
+
client = storage.Client()
|
5 |
+
|
6 |
+
# Define bucket and file name
|
7 |
+
bucket_name = 'your-bucket-name'
|
8 |
+
file_name = 'your-file.glb'
|
9 |
+
|
10 |
+
# Function to upload a .glb file to the bucket
|
11 |
+
def upload_file(file_path):
|
12 |
+
bucket = client.get_bucket(bucket_name)
|
13 |
+
blob = bucket.blob(file_name)
|
14 |
+
blob.upload_from_filename(file_path)
|
15 |
+
print(f'File {file_name} uploaded to {bucket_name}.')
|
16 |
+
|
17 |
+
# Function to download a .glb file from the bucket
|
18 |
+
def download_file(destination_path):
|
19 |
+
bucket = client.get_bucket(bucket_name)
|
20 |
+
blob = bucket.blob(file_name)
|
21 |
+
blob.download_to_filename(destination_path)
|
22 |
+
print(f'File {file_name} downloaded to {destination_path}.')
|
23 |
+
|
24 |
+
# Function to delete a .glb file from the bucket
|
25 |
+
def delete_file():
|
26 |
+
bucket = client.get_bucket(bucket_name)
|
27 |
+
blob = bucket.blob(file_name)
|
28 |
+
blob.delete()
|
29 |
+
print(f'File {file_name} deleted from {bucket_name}.')
|
30 |
+
|
31 |
+
def main():
|
32 |
+
# Example usage
|
33 |
+
upload_file('path/to/your/file.glb')
|
34 |
+
download_file('path/to/save/your/file.glb')
|
35 |
+
delete_file()
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
main()
|