티스토리 뷰
Python
ncloud python3 boto3 s3 오브젝트 스토리지 업로드 예제 object storage upload example
j0n9m1n1 2019. 11. 21. 14:38반응형
import boto3
services_name = 's3'
endpoint_url = 'https://kr.object.ncloudstorage.com'
region_name = 'kr-standard'
access_key = ''
secret_key = ''
class Storage():
def __init__(self):
s3 = boto3.client(services_name,
endpoint_url=endpoint_url,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key)
def create_bucket(self, bname):
bucket_name = bname # '-' 안 됨
self.s3.create_bucket(Bucket=bucket_name)
def delete_bucket(self, bname):
bucket_name = bname
self.s3.delete_bucket(Bucket=bucket_name)
def get_bucket_list(self):
response = self.s3.list_buckets()
for b in response.get('Buckets', []): print(b.get('Name'))
def create_bucket_dir(self, bname, cpath):
bucket_name = bname
cloud_object_name = cpath # create dir
self.s3.put_object(Bucket=bucket_name, Key=cloud_object_name) # create dir
def obj_upload(self, bname, cpath, cfilename):
cloud_full_path = f'{cpath}sample_text.txt' # upload path on cloud
local_file_path = 'I:/all/ncloud/upload_test.txt' # upload target on local
self.s3.upload_file(local_file_path, bname, cloud_full_path)
def obj_download(self):
bucket_name = 'office_test'
object_name1 = 'office_folder/upload_test.txt' # download target cloud path+filename
local_file_path = 'I:/all/ncloud/download.txt' # download local path+filename
self.s3.download_file(bucket_name, object_name1, local_file_path)
def main():
storage = Storage()
storage.create_bucket('uploadtestest')
# storage.obj_upload('office_test', 'sample_folder/')
if __name__ == "__main__":
main()
https://docs.ncloud.com/ko/storage/storage-8-2.html
ncloud object storage는 amazon signature key인가 v3버전임
chilkat, aws sdk c++ 모두 붙음
'Python' 카테고리의 다른 글
Baekjoon 백준 12790번 Mini Fantasy War (0) | 2020.02.21 |
---|---|
Baekjoon 백준 2751번 수 정렬하기 2 (0) | 2020.02.21 |
tesseract-OCR 환경변수 (0) | 2020.02.11 |
Python Oracle cx_oracle연동 (0) | 2019.11.04 |
Oracle Cloud oci로 인증 방법 (0) | 2019.10.23 |
댓글
티스토리 방명록
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
Blog is powered by
Tistory / Designed by
Tistory
Contact: j0n9m1n1@gmail.com
Contact: j0n9m1n1@gmail.com