cURL
사용
IBM Cloud® Object Storage 및 cURL
을 사용하는 대부분의 환경에서 명령행을 통한 작업을 최대한 활용할 수 있습니다.
여기에는 IBM Cloud® Object Storage REST API에 대한 기본 curl
명령의 '치트 시트'가 있습니다. 세부사항은 버킷 또는 오브젝트에
대한 API 참조에 있습니다.
curl
사용 시 명령행 및 Object Storage에 어느 정도 익숙하고 서비스 인증 정보, 엔드포인트 참조 또는
콘솔에서 필요한 정보를 가져왔다고 가정합니다. 용어나 변수가 익숙하지 않은 경우 용어집에서 찾을 수 있습니다.
참고: PII (Personally Identifiable Information): 이름 지정 버킷 또는 오브젝트의 경우 이름, 위치 또는 기타 방법으로 사용자 (자연 사용자) 를 식별할 수 있는 정보를 사용하지 마십시오.
IAM 토큰 요청
요청을 인증하기 위해 IAM oauth
토큰을 생성하는 두 가지 방법은 API 키와 함께 curl
명령을 사용하거나(나중에 설명됨) 명령행에서 IBM Cloud® CLI를 사용하는 것입니다.
API 키를 사용하여 IAM 토큰 요청
API 키가 있는지 확인하십시오. IBM Cloud® Identity and Access Management에서 가져올 수 있습니다.
curl -X "POST" "https://iam.cloud.ibm.com/oidc/token" \
-H 'Accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode "apikey={api-key}" \
--data-urlencode "response_type=cloud_iam" \
--data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey"
리소스 인스턴스 ID 가져오기
다음 명령 중 일부에는 ibm-service-instance-id
매개변수가 필요합니다. 이 값을 찾으려면 클라우드 콘솔에 있는 오브젝트 스토리지 인스턴스의 서비스 인증 정보 탭으로 이동하십시오. 필요한 경우 인증 정보를 작성한 다음 인증 정보 보기 메뉴를 사용하여 JSON 형식을 확인하십시오. resource_instance_id
값을
사용하십시오.
curl API에서 사용하려면 마지막 단일 콜론 다음에 시작하여 마지막 이중 콜론 앞에서 끝나는 UUID만 필요합니다. 예를 들어, ID crn:v1:bluemix:public:cloud-object-storage:global:a/81caa0254631ce5f9330ae427618f209:39d8d161-22c4-4b77-a856-f11db5130d7d::
는 39d8d161-22c4-4b77-a856-f11db5130d7d
로
축약될 수 있습니다.
버킷 나열
curl "https://(endpoint)/"
-H "Authorization: bearer (token)"
-H "ibm-service-instance-id: (resource-instance-id)"
버킷 추가
curl -X "PUT" "https://(endpoint)/(bucket-name)"
-H "Authorization: Bearer (token)"
-H "ibm-service-instance-id: (resource-instance-id)"
버킷 추가(스토리지 클래스)
curl -X "PUT" "https://(endpoint)/(bucket-name)"
-H "Content-Type: text/plain; charset=utf-8"
-H "Authorization: Bearer (token)"
-H "ibm-service-instance-id: (resource-instance-id)"
-d "<CreateBucketConfiguration>
<LocationConstraint>(provisioning-code)</LocationConstraint>
</CreateBucketConfiguration>"
LocationConstraint
에 대한 유효한 코드의 목록은 스토리지 클래스 안내서에서 참조할 수 있습니다.
버킷 CORS 작성
curl -X "PUT" "https://(endpoint)/(bucket-name)/?cors"
-H "Content-MD5: (md5-hash)"
-H "Authorization: bearer (token)"
-H "Content-Type: text/plain; charset=utf-8"
-d "<CORSConfiguration>
<CORSRule>
<AllowedOrigin>(url)</AllowedOrigin>
<AllowedMethod>(request-type)</AllowedMethod>
<AllowedHeader>(url)</AllowedHeader>
</CORSRule>
</CORSConfiguration>"
Content-MD5
헤더는 base64 인코딩 MD5 해시의 2진 표시여야 합니다.
echo -n (XML block) | openssl dgst -md5 -binary | openssl enc -base64
버킷 CORS 가져오기
curl "https://(endpoint)/(bucket-name)/?cors"
-H "Authorization: bearer (token)"
버킷 CORS 삭제
curl -X "DELETE" "https://(endpoint)/(bucket-name)/?cors"
-H "Authorization: bearer (token)"
오브젝트 나열
curl "https://(endpoint)/(bucket-name)"
-H "Authorization: bearer (token)"
버켓 헤더 가져오기
curl --head "https://(endpoint)/(bucket-name)/"
-H "Authorization: bearer (token)"
버켓 메타데이터 가져오기
구성 API 엔드포인트의 사용은 버킷 자체의 엔드포인트와 동일하지 않습니다. 이 명령을 사용하면 지정된 버킷에 대한 메타데이터가 리턴됩니다.
curl https://config.cloud-object-storage.cloud.ibm.com/v1/b/{my-bucket} \
-H 'authorization: bearer <IAM_token>'
버킷 삭제
curl -X "DELETE" "https://(endpoint)/(bucket-name)/"
-H "Authorization: bearer (token)"
오브젝트 업로드
curl -X "PUT" "https://(endpoint)/(bucket-name)/(object-key)" \
-H "Authorization: bearer (token)" \
-H "Content-Type: (content-type)" \
-d "(object-contents)"
오브젝트의 헤더 가져오기
curl --head "https://(endpoint)/(bucket-name)/(object-key)"
-H "Authorization: bearer (token)"
오브젝트 복사
curl -X "PUT" "https://(endpoint)/(bucket-name)/(object-key)"
-H "Authorization: bearer (token)"
-H "x-amz-copy-source: /(bucket-name)/(object-key)"
CORS 정보 확인
curl -X "OPTIONS" "https://(endpoint)/(bucket-name)/(object-key)"
-H "Access-Control-Request-Method: PUT"
-H "Origin: http://(url)"
오브젝트 다운로드
curl "https://(endpoint)/(bucket-name)/(object-key)"
-H "Authorization: bearer (token)"
오브젝트의 ACL 확인
curl "https://(endpoint)/(bucket-name)/(object-key)?acl"
-H "Authorization: bearer (token)"
방화벽 사용
구성 API 엔드포인트의 사용은 버킷 자체의 엔드포인트와 동일하지 않습니다. 이 명령을 사용하면 지정된 버킷에 대한 방화벽이 사용으로 설정됩니다. 방화벽이 활성 상태이면 다른 IBM Cloud® 서비스가 버킷에 액세스할 수 없습니다.
curl -X PATCH https://config.cloud-object-storage.cloud.ibm.com/v1/b/{my-bucket} \
-H 'authorization: bearer $IAM_TOKEN' \
-d '{"firewall": {"allowed_ip": ["10.142.175.0/22", "10.198.243.79"]}}'
활동 추적 사용
구성 API 엔드포인트의 사용은 버킷 자체에 대한 엔드포인트와 동일하지 않습니다. 이 명령을 사용하면 지정된 버킷에 대한 활동 추적이 사용으로 설정됩니다.
curl -X PATCH https://config.cloud-object-storage.cloud.ibm.com/v1/b/{my-bucket} \
-H 'authorization: bearer <IAM_token>' \
-d '{"activity_tracking": { \
"read_data_events": True, \
"write_data_events": True}'
오브젝트에 대한 익명의 액세스 허용
curl -X "PUT" "https://(endpoint)/(bucket-name)/(object-key)?acl"
-H "Content-Type: (content-type)"
-H "Authorization: bearer (token)"
-H "x-amz-acl: public-read"
오브젝트 삭제
curl -X "DELETE" "https://(endpoint)/(bucket-name)/(object-key)"
-H "Authorization: bearer (token)"
다중 오브젝트 삭제
curl -X "POST" "https://(endpoint)/(bucket-name)?delete"
-H "Content-MD5: (md5-hash)"
-H "Authorization: bearer (token)"
-H "Content-Type: text/plain; charset=utf-8"
-d "<?xml version="1.0" encoding="UTF-8"?>
<Delete>
<Object>
<Key>(first-object)</Key>
</Object>
<Object>
<Key>(second-object)</Key>
</Object>
</Delete>"
Content-MD5
헤더는 base64 인코딩 MD5 해시의 2진 표시여야 합니다.
echo -n (XML block) | openssl dgst -md5 -binary | openssl enc -base64
다중 파트 업로드 시작
curl -X "POST" "https://(endpoint)/(bucket-name)/(object-key)?uploads"
-H "Authorization: bearer (token)"
파트 업로드
curl -X "PUT" "https://(endpoint)/(bucket-name)/(object-key)?partNumber=(sequential-integer)&uploadId=(upload-id)"
-H "Authorization: bearer (token)"
-H "Content-Type: (content-type)"
다중 파트 업로드 완료
curl -X "POST" "https://(endpoint)/(bucket-name)/(object-key)?uploadId=(upload-id)"
-H "Authorization: bearer (token)"
-H "Content-Type: text/plain; charset=utf-8"
-d "<CompleteMultipartUpload>
<Part>
<PartNumber>1</PartNumber>
<ETag>(etag)</ETag>
</Part>
<Part>
<PartNumber>2</PartNumber>
<ETag>(etag)</ETag>
</Part>
</CompleteMultipartUpload>"
불완전한 다중 파트 업로드 가져오기
curl "https://(endpoint)/(bucket-name)/?uploads"
-H "Authorization: bearer (token)"
불완전한 다중 파트 업로드 중지
curl -X "DELETE" "https://(endpoint)/(bucket-name)/(object-key)?uploadId"
-H "Authorization: bearer (token)"
정적 웹 사이트 구성
curl --location --request PUT 'https://<endpoint>/<bucketname>?website' \
--header 'Authorization: bearer <token>' --header 'ibm-service-instance-id: <resource_instance_id> \
--header 'Content-MD5: <hashed-output>' --header 'Content-Type: text/plain' \
--data-raw '<WebsiteConfiguration>
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>error.html</Key>
</ErrorDocument>
</WebsiteConfiguration>'
Content-MD5
헤더는 base64-encoded MD5 해시의 2진 표현이어야 합니다.
echo -n (XML block) | openssl dgst -md5 -binary | openssl enc -base64
다음 단계
IBM Cloud Object Storage 용 RESTful API에 대한 자세한 설명은 S3 호환성 API 문서 또는 구성 API 문서에서 찾을 수 있습니다.