반응형
Notice
Recent Posts
Recent Comments
Link
둘에서 하나로....
파이썬으로 네이버 object storage(s3)에 파일 2천개 업로드(파일명 변경후) 하는 방법 본문
반응형
우선 boto3를 설치한다.
pip install boto3
import boto3
from pathlib import Path
import sys
service_name = 's3'
endpoint_url = 'https://kr.object.ncloudstorage.com' # aws에 업로드할경우 삭제
region_name = 'kr-standard'
access_key = '엑세스키'
secret_key = '시크릿키'
if __name__ == "__main__":
s3 = boto3.client(service_name, endpoint_url=endpoint_url, aws_access_key_id=access_key,
aws_secret_access_key=secret_key)
bucket_name = '버킷이름'
f = open('list.txt', 'w') # 순차적인 파일명 별도의 파일로 기록한다.
i = 1
for 파일 in Path("./img").iterdir(): # img폴더의 파일을 읽어들인다.
print(i,파일)
tmp = str(i)+".jpg" # 해당 이미지를 순차적인 숫자로 변경한다.
print(tmp+"|"+str(파일), file=f) # list.txt에 현재 변경된 파일명을 추가한다.
# upload file
object_name = 'imgs/'+tmp
local_file_path = 파일
s3.upload_file(local_file_path, bucket_name, object_name) #파일을 업로드 한다.
i = i + 1
f.close()
반응형
0 Comments