Spaces:
Sleeping
Sleeping
Create store_pdb.py
Browse files- store_pdb.py +29 -0
store_pdb.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import boto3
|
| 2 |
+
import io
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
cloud_flare_bucket_accesskey="98656529f35f5a57e1adab0f51ff534c"
|
| 6 |
+
cloud_flare_bucket_accesssecret="161c41521a4fbba92fc9a5e79577bd63c92575824b9c5e37e95d1c7f0a70dec5"
|
| 7 |
+
bucket_url="https://bdb69ad76af47aa51feb9051e0fa5287.r2.cloudflarestorage.com"
|
| 8 |
+
|
| 9 |
+
s3 = boto3.client(
|
| 10 |
+
service_name ="s3",
|
| 11 |
+
endpoint_url = bucket_url,
|
| 12 |
+
aws_access_key_id = cloud_flare_bucket_accesskey,
|
| 13 |
+
aws_secret_access_key = cloud_flare_bucket_accesssecret,
|
| 14 |
+
region_name="apac"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
def StorePDB_CloudFlare(pdb_content,filename):
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
|
| 21 |
+
file_obj = io.BytesIO(pdb_content.encode('utf-8'))
|
| 22 |
+
|
| 23 |
+
s3.upload_fileobj(file_obj, "xforce-pdb-storage",filename)
|
| 24 |
+
public_url = f"https://pub-0ef061d7beb2472099b60c1d073ef098.r2.dev/{filename}"
|
| 25 |
+
print("✅ Uploaded successfully.")
|
| 26 |
+
return True,public_url
|
| 27 |
+
|
| 28 |
+
except Exception as e:
|
| 29 |
+
return False,""
|