I am trying to use python requests library to send a file to Google Drive api. The only thing I need it to send a multipart request according to google documentation https:/
I figured out a way to do it. The problem is Google wants the meta data and the file together.
def upload_csv(self, file, description):
self.refresh()
url = self.url+'?uploadType=multipart&convert=true' + urllib.urlencode({'key':self.api_key})
headers = { 'Authorization':'Bearer {}'.format(self.access_token) }
class DataDict(dict):
def read(self):
return str( self )
data = ('metadata',DataDict(title = file,description = description),'application/json; charset=UTF-8')
file = (file,open(file,'rb'),'text/csv')
files = {'data':data, 'file':file }
response = requests.post( url, headers = headers, files = files )
return respone