我想使用 Google Script 和 Python 将文件上传到 Google Drive.
I want to upload files to Google Drive with Google Script and Python.
我不想使用 API 执行此操作,因为它使用 JSON 文件并请求 Google 帐户的密码.
I don't want to do this with API because it's with JSON file and requesting a password to google account.
我想从没有 JSON 文件且不请求谷歌帐户的 Python 文件发送.
I want to send from the Python file without a JSON file and without requesting a google account.
我想在谷歌脚本中创建一个脚本,将文件上传到网站.
I want to create a script in google script that will upload the file to the site.
我找到了如何使用 html 来做到这一点:
I found how to do it with html:
function saveFile(data,name,folderName) {
var contentType = data.substring(5,data.indexOf(';'));
var file = Utilities.newBlob(
Utilities.base64Decode(data.substr(data.indexOf('base64,')+7)),
contentType,
name
); //does the uploading of the files
DriveApp.getFolderById(childFolderIdA).createFile(file);
}
但是我没有找到如何用 python 来做.
But I did not find how to do it with python.
如何将带有文件的文件发送到此代码?
How do I send file with file to this code?
您可以通过发布一个网络应用程序以我"(您)的身份运行并访问:任何人,甚至匿名".
You can do this by publishing a web app to run as "Me"(you) with access: "Anyone, even anonymous".
function doPost(e){
const FOLDER_ID = '###FOLDER_ID###';
var name = e.parameter.name;
saveFile(e.postData.contents,name,FOLDER_ID);
return 'Success';
}
function saveFile(data,name,id) {
data = Utilities.newBlob(Utilities.base64DecodeWebSafe(data));
DriveApp.getFolderById(id)
.createFile(data.setName(name))
}
import requests, base64
url = '###WEB_APP_PUBLISHED_URL###'
name = '###FILENAME###'
requests.post(url+'?name='+name,data=base64.urlsafe_b64encode(open('##UPLOAD FILE PATH##','rb').read()))
这篇关于如何在没有身份验证的情况下使用 python 上传到谷歌驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
使用 python 解析非常大的 xml 文件时出现问题Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件时出现问题)
使用 Python 2 在 XML 中按属性查找所有节点Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按属性查找所有节点)
Python - 如何解析 xml 响应并将元素值存储在变量中Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 响应并将元素值存储在变量中?)
如何在 Python 中获取 XML 标记值How to get XML tag value in Python(如何在 Python 中获取 XML 标记值)
如何使用 ElementTree 正确解析 utf-8 xml?How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正确解析 utf-8 xml?)
将 XML 从 URL 解析为 python 对象Parse XML from URL into python object(将 XML 从 URL 解析为 python 对象)