2017-02-23 2 views
1

Curl 및 API 키를 사용하여 Google Cloud Storage에 업로드하지 않고 성공하려고합니다. 오류 메시지는 내가 Content-length 헤더가 없다는 것을 나타내는 것 같습니다. 어떤 아이디어?Curl 및 API 키를 사용하여 Google Cloud Storage에 업로드하려면 어떻게해야합니까?

$ curl -v -T ./myfile -X POST https://storage.googleapis.com/my-app/my-bucket/myfile?key=<my-api-token> 
> Host: storage.googleapis.com 
> User-Agent: curl/7.51.0 
> Accept: */* 
> Content-Length: 4 
> Expect: 100-continue 
> 
< HTTP/1.1 100 Continue 
* We are completely uploaded and fine 
< HTTP/1.1 411 Length Required 
< Date: Thu, 23 Feb 2017 13:46:59 GMT 
< Content-Type: text/html; charset=UTF-8 
< Server: UploadServer 
< Content-Length: 1564 
< Alt-Svc: quic=":443"; ma=2592000; v="36,35,34" 
< Connection: close 
< 
<!DOCTYPE html> 
<html lang=en> 
    <meta charset=utf-8> 
    <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width"> 
    <title>Error 411 (Length Required)!!1</title> 
    <style> 
    [snip snip] 
    </style> 
    <a href=//www.google.com/><span id=logo aria-label=Google></span></a> 
    <p><b>411.</b> <ins>That’s an error.</ins> 
    <p>POST requests require a <code>Content-length</code> header. <ins>That’s all we know.</ins> 
* Curl_http_done: called premature == 0 
* Closing connection 0 

답변

5

API 키는 인증을 제공하지 않습니다. 할당량 및 기타 몇 가지 목적으로 통화를 프로젝트와 연결하지만 익명 액세스 이외의 다른 리소스가 필요한 액세스에는 사용할 수 없습니다.

"액세스 키"는 일반적으로 OAuth 교환을 통해 다양한 방법으로 획득 할 수 있습니다. gcloud 명령이 설치되어있는 경우 cURL과 함께 사용하는 빠른 액세스 키를 가져 오는 가장 쉬운 방법은 gcloud auth print-access-token입니다. 다음 작동해야합니다 :

$> curl -v --upload-file my-file.txt \ 
    -H "Authorization: Bearer `gcloud auth print-access-token`" \ 
    'https://storage.googleapis.com/my-bucket/my-file.txt' 
+0

감사! 이제 다른 오류가 발생합니다. 'InvalidArgument 잘못된 인수입니다.

POST 객체에 Content-Type multipart/form-data가 필요합니다.
neu242

+1

현재 사용하고있는 곱슬 곱슬 명령은 무엇입니까? PUT 대신 POST를하고있는 것처럼 보입니다. –

+0

그게 다야! 나는 아직도 명령에서'-X POST'를 가지고있다. 감사. – neu242