Mryqu's Notes


  • 首页

  • 搜索
close

Upload file to Google Drive using Postman and cURL

时间: 2017-01-03   |   分类: DataBuilder     |   阅读: 233 字 ~2分钟

Simple upload

For quick transfer of smaller files, for example, 5 MB or less.

Postman

postman: google drive simple upload postman: google drive simple upload result

cURL

curl -T mytest.csv -X POST -H "Content-Type: text/csv" -H "Cache-Control: no-cache" "https://www.googleapis.com/upload/drive/v3/files?uploadType=media&access_token={YOUR_ACCESS_TOKEN}"

Multipart upload

For quick transfer of smaller files and metadata; transfers the file along with metadata that describes it, all in a single request.

Postman

postman: google drive multipart upload postman: google drive multipart upload result At the beginning, I try to use form-data for body, then the second value can use file directly. But Postman can’t configure Content-Type for each part, and Google Drive return error. I use raw data for body finally.

cURL

curl -X POST -H "Content-Type: multipart/related; boundary=foo_bar_baz" -H "Cache-Control: no-cache" -d '--foo_bar_baz
Content-Type: application/json; charset=UTF-8

{
  "name": "postman-gdmultipartupload"
}

--foo_bar_baz
Content-Type: text/csv

Name,Sex,Age,Height,Weight
Alfred,M,14,69,112.5
Alice,F,13,56.5,84
Barbara,F,13,65.3,98
Carol,F,14,62.8,102.5
--foo_bar_baz--' "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&access_token={YOUR_ACCESS_TOKEN}"

Resumable upload

For reliable transfer, especially important with larger files. With this method, you use a session initiating request, which optionally can include metadata. This is a good strategy to use for most applications, since it also works for smaller files at the cost of one additional HTTP request per upload.

Postman

postman: google drive resumable upload - step 1 postman: google drive resumable upload - step 2

cURL

curl -X POST -H "Content-Type: application/json; charset=UTF-8" -H "X-Upload-Content-Type: text/csv" -H "Cache-Control: no-cache" -d '{
  "name": "postman-gdresumableupload"
}' "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&access_token={YOUR_ACCESS_TOKEN}"

curl -X PUT -H "Content-Type: text/csv" -H "Cache-Control: no-cache" -d 'Name,Sex,Age,Height,Weight
Alfred,M,14,69,112.5
Alice,F,13,56.5,84
Barbara,F,13,65.3,98
Carol,F,14,62.8,102.5' "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&access_token={YOUR_ACCESS_TOKEN}&upload_id={GOTTEN_UOLOAD_ID}"

Reference


Google Drive APIs - REST - Upload Files
libcurl fileupload example
libcurl http2-upload example
libcurl postit2 example
libcurl multi-post example
libcurl ftpuploadresume example

标题:Upload file to Google Drive using Postman and cURL
作者:mryqu
声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 CN 许可协议。转载请注明出处!

#upload# #google drive# #postman# #curl#
Upload file to Google Drive using LibCurl
在Google Drive上创建存在多个目录下的文件
  • 文章目录
  • 站点概览

Programmer & Architect

662 日志
27 分类
1472 标签
GitHub Twitter FB Page
    • Simple upload
    • Multipart upload
    • Resumable upload
    • Reference
© 2009 - 2023 Mryqu's Notes
Powered by - Hugo v0.120.4
Theme by - NexT
0%