Python Forum
how to upload a file to my gmail driver after login ??
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to upload a file to my gmail driver after login ??
#3
i solved the multi files issue by adding (i)

import json
 
import requests
import glob
 
 
     
 
def upload_1():
         
    headers = {"Authorization": "Bearer access token"} #put ur access token after the word 'Bearer '
    qassam = glob.glob("/root/Downloads/*.pdf")
    for i in qassam:
        qassam = "\n".join(qassam)  
        print i
 
         
        para = {
            "name": (i), #file name to be uploaded
            "parents": ["1bEBQugJ4GVnEECElKztEgq9tHbFdYetu"] # make a folder on drive in which you want to upload files; then open that folder; the last thing in present url will be folder id
        }
        files = {
            'data': ('metadata', json.dumps(para), 'application/json; charset=UTF-8'),
            'file': ('application/zip',open(i, "rb")) # replace 'application/zip' by 'image/png' for png images; similarly 'image/jpeg' (also replace your file name)
        }
        r = requests.post(
            "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
            headers=headers,
            files=files
        )
        print(r.text)
 
upload_1()
but i have a new issue !! the access token is expired every 1 hour !! so i must go the : https://developers.google.com/oauthplayground/ and get the new one and replace it manually !! i dont need that i need to do this auto !! is there anyway to get a new token by python !!
Reply


Messages In This Thread
RE: how to upload a file to my gmail driver after login ?? - by evilcode1 - Nov-05-2018, 08:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 304 Mar-28-2024, 01:46 PM
Last Post: Username_Python1
  Extract PDF Attachment from Gmail jstaffon 0 597 Sep-10-2023, 01:55 PM
Last Post: jstaffon
  '' FTP '' File upload with a specified string and rename midomarc 1 1,200 Apr-17-2023, 03:04 AM
Last Post: bowlofred
  Python code a Max7219/7221 7 segment driver Aggie64 11 3,216 Dec-01-2022, 02:24 AM
Last Post: Larz60+
  Unable to upload file using FTP korenron 2 2,519 Dec-23-2021, 12:44 PM
Last Post: korenron
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,239 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Stepper motor/Easy Driver/HELP Harney 1 1,913 Jul-31-2021, 08:05 AM
Last Post: Harney
  Gmail Sent email LIMIT Johnse 5 7,178 Apr-28-2021, 10:19 PM
Last Post: snippsat
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 2,308 Feb-20-2021, 04:43 AM
Last Post: bowlofred
Photo Raspberry PI writing to RS485 driver, DIR pin not holding state zazas321 2 2,149 Oct-30-2020, 06:23 AM
Last Post: zazas321

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020