티스토리 뷰

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

 

설명서

Python SDK for S3 API AWS S3에서 제공하는 Python SDK를 이용하여 네이버 클라우드 플랫폼 Object Storage를 사용하는 방법을 설명합니다. 이 문서는 AWS Python SDK 1.6.19 버전을 기준으로 작성되었습니다. 설치 pip install boto3==1.6.19 AWS Python SDK 예제 예제에서 사용하는 access_key, secret_key는 등록한 API 인증키 정보로 입력해야 합니다. 버킷 생성

docs.ncloud.com

 

ncloud object storage는 amazon signature key인가 v3버전임

chilkat, aws sdk c++ 모두 붙음