2016-06-09 2 views
0

Google API의 link을 기반으로합니다. 큰 파일 크기 때문에 Multipart 업로드를 사용하고 싶습니다. 하지만 그건 내가 이해하지 못하는 것이 많다. 제발 고급. 구글 API 문서를 기반으로 Google 드라이브를 사용하여 Google API를 사용하여 파일 업로드

POST https://www.googleapis.com/upload/drive/v3/files?uploadType=media 

나는 시도는 다음과 같습니다 해요하지만 구글 REST 링크에서

https://www.googleapis.com/upload/drive/v3/C:\Users\RNKP74\Desktop\Full_XML.zip?uploadType=media 

작동하지 무엇, 그것은 예를 보여 간단한 업로드를 사용하려면 아래와 같이 어떻게 실행합니까?

POST /upload/drive/v3/files?uploadType=multipart HTTP/1.1 
Host: www.googleapis.com 
Authorization: Bearer your_auth_token 
Content-Type: multipart/related; boundary=foo_bar_baz 
Content-Length: number_of_bytes_in_entire_request_body 

--foo_bar_baz 
Content-Type: application/json; charset=UTF-8 

{ 
    "name": "My File" 
} 

--foo_bar_baz 
Content-Type: image/jpeg 

JPEG data 
--foo_bar_baz-- 
+0

누구나 Google 드라이브에 파일을 업로드하는 방법을 알려 줄 수 있습니까? 모든 설정은 끝났어. – Yeep

+0

조회 POST 대 GET. –

답변

0

사용 Files:insert이 방법은/업로드 URI를 지원하며 업로드 된 미디어를 허용합니다. Official Google Documentation에는 예제가 들어 있습니다.

먼저 드라이브 메타 데이터에 새 파일 메타 데이터를 게시하십시오. 그것은 File resource JSON object의 형태로되어야한다 :

POST /drive/v2/files HTTP/1.1 
Host: www.googleapis.com 
Authorization: Bearer <OAuth 2.0 access token here> 
... 

{ 
"title": "file_name.extension", 
"mimeType": "mime/type", 
"description": "Stuff about the file" 
} 

응답 기관은 새로 생성 된 파일 자원의 JSON 표현 될 것입니다. 다음과 같이 표시됩니다.

{ 
"kind": "drive#file", 
"id": string, 
"etag": etag, 
"selfLink": string, 
"title": "file_name", 
"mimeType": "mime/type", 
"description": "Stuff about the file" 
... 
"downloadUrl": string, 
... 
} 

파일 항목이 생성되었는지 확인합니다. 이제 콘텐츠를 업로드해야합니다. 그렇게하려면 위 응답에서 id JSON 속성으로 지정된 파일의 ID를 가져 와서 OAuth 2.0 승인 요청을 사용하여 실제 파일의 내용을 업로드 엔드 포인트로 가져와야합니다. 또한 Resumable upload을 필요로 할 수있다

PUT /upload/drive/v2/files/{id}?uploadType=media HTTP/1.1 
Host: www.googleapis.com 
Authorization: Bearer <OAuth 2.0 access token here> 
Content-Type: mime/type 

<file content here> 

A로부터 업로드 할 때, 예를 들어, 대용량 파일 및 네트워크 중단의 가능성 또는 다른 전송 실패가 높은를 양도하는 경우 특히 유용합니다 것처럼 보일 것입니다 모바일 클라이언트 앱. 처음부터 대용량 파일 업로드를 다시 시작할 필요가 없기 때문에 네트워크 장애시에도 대역폭 사용량을 줄일 수 있습니다.

관련 문제