我想直接將一些檔案從谷歌驅動器上傳到亞馬遜 s3,但無法這樣做。
我不知道,如何將檔案從谷歌驅動器直接上傳到亞馬遜 s3。
我嘗試使用 python 和 google api 獲取下載鏈接。
但是當我嘗試上傳到亞馬遜 s3 時出現錯誤:
axios
.get("https://drive.google.com/u/0/uc?id=" id "&export=download", {
responseType: 'arraybuffer',
withCredentials: false,
headers:{
'Authorization':'Bearer: <access_token>',
'Content-Type': 'text/plain'
}
})
.then((response:any) => Buffer.from(response.data, 'binary'))
.then((data:any)=>{
console.log(data)
})
錯誤
has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
誰能告訴我,我該如何解決這個錯誤?
uj5u.com熱心網友回復:
然后你從驅動器中獲得了資料;使用aws-sdk包,您可以創建
s3 = new AWS.S3(....)
然后使用s3.putObject 方法
uj5u.com熱心網友回復:
設法找到答案并將其作為答案發布給正在尋找相同答案的任何人:
首先,您需要一個可下載的鏈接,您可以使用檔案 ID 構建該鏈接:
這里是:
"https://www.googleapis.com/drive/v3/files/" file.id '?alt=media'
然后您可以使用您的 google 訪問令牌發出 GET 請求:
'Authorization','Bearer ' accessToken
這樣你就可以從谷歌驅動器下載檔案,你可以上傳到s3。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/342433.html
