Add upload progress to Google Drive script using python





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















This is my code:



media_body = MediaFileUpload(file_name , resumable=True)
body = {
'title': file_name,
'description': 'Uploaded By Bardulf'}
file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink').execute()
if file:
print(file_name + " uploaded successfully")
prem = DRIVE.permissions().insert( fileId=file.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True}).execute()
print ("Your sharable link: "+ "https://drive.google.com/file/d/" + file.get('id')+'/view')


I want add progress bar, so I use this documentation, add change my code to:



media_body = MediaFileUpload(file_name , resumable=True)
body = {
'title': file_name,
'description': 'Uploaded By Bardulf'}
file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink').execute()
if file:
print(file_name + " uploaded successfully")
prem = DRIVE.permissions().insert( fileId=file.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True})
response = None
while response is None:
status, response = prem.next_chunk()
if status:
print ("Uploaded %d%%." % int(status.progress() * 100))

print ("Your sharable link: "+ "https://drive.google.com/file/d/" + file.get('id')+'/view')


When I run my script I get:



    status, response = prem.next_chunk()
File "/usr/local/lib/python3.5/dist-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/googleapiclient/http.py", line 899, in next_chunk
if self.resumable.size() is None:
AttributeError: 'NoneType' object has no attribute 'size'


I use api v2 and python 3.5










share|improve this question





























    0















    This is my code:



    media_body = MediaFileUpload(file_name , resumable=True)
    body = {
    'title': file_name,
    'description': 'Uploaded By Bardulf'}
    file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink').execute()
    if file:
    print(file_name + " uploaded successfully")
    prem = DRIVE.permissions().insert( fileId=file.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True}).execute()
    print ("Your sharable link: "+ "https://drive.google.com/file/d/" + file.get('id')+'/view')


    I want add progress bar, so I use this documentation, add change my code to:



    media_body = MediaFileUpload(file_name , resumable=True)
    body = {
    'title': file_name,
    'description': 'Uploaded By Bardulf'}
    file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink').execute()
    if file:
    print(file_name + " uploaded successfully")
    prem = DRIVE.permissions().insert( fileId=file.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True})
    response = None
    while response is None:
    status, response = prem.next_chunk()
    if status:
    print ("Uploaded %d%%." % int(status.progress() * 100))

    print ("Your sharable link: "+ "https://drive.google.com/file/d/" + file.get('id')+'/view')


    When I run my script I get:



        status, response = prem.next_chunk()
    File "/usr/local/lib/python3.5/dist-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
    File "/usr/local/lib/python3.5/dist-packages/googleapiclient/http.py", line 899, in next_chunk
    if self.resumable.size() is None:
    AttributeError: 'NoneType' object has no attribute 'size'


    I use api v2 and python 3.5










    share|improve this question

























      0












      0








      0








      This is my code:



      media_body = MediaFileUpload(file_name , resumable=True)
      body = {
      'title': file_name,
      'description': 'Uploaded By Bardulf'}
      file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink').execute()
      if file:
      print(file_name + " uploaded successfully")
      prem = DRIVE.permissions().insert( fileId=file.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True}).execute()
      print ("Your sharable link: "+ "https://drive.google.com/file/d/" + file.get('id')+'/view')


      I want add progress bar, so I use this documentation, add change my code to:



      media_body = MediaFileUpload(file_name , resumable=True)
      body = {
      'title': file_name,
      'description': 'Uploaded By Bardulf'}
      file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink').execute()
      if file:
      print(file_name + " uploaded successfully")
      prem = DRIVE.permissions().insert( fileId=file.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True})
      response = None
      while response is None:
      status, response = prem.next_chunk()
      if status:
      print ("Uploaded %d%%." % int(status.progress() * 100))

      print ("Your sharable link: "+ "https://drive.google.com/file/d/" + file.get('id')+'/view')


      When I run my script I get:



          status, response = prem.next_chunk()
      File "/usr/local/lib/python3.5/dist-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
      return wrapped(*args, **kwargs)
      File "/usr/local/lib/python3.5/dist-packages/googleapiclient/http.py", line 899, in next_chunk
      if self.resumable.size() is None:
      AttributeError: 'NoneType' object has no attribute 'size'


      I use api v2 and python 3.5










      share|improve this question














      This is my code:



      media_body = MediaFileUpload(file_name , resumable=True)
      body = {
      'title': file_name,
      'description': 'Uploaded By Bardulf'}
      file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink').execute()
      if file:
      print(file_name + " uploaded successfully")
      prem = DRIVE.permissions().insert( fileId=file.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True}).execute()
      print ("Your sharable link: "+ "https://drive.google.com/file/d/" + file.get('id')+'/view')


      I want add progress bar, so I use this documentation, add change my code to:



      media_body = MediaFileUpload(file_name , resumable=True)
      body = {
      'title': file_name,
      'description': 'Uploaded By Bardulf'}
      file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink').execute()
      if file:
      print(file_name + " uploaded successfully")
      prem = DRIVE.permissions().insert( fileId=file.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True})
      response = None
      while response is None:
      status, response = prem.next_chunk()
      if status:
      print ("Uploaded %d%%." % int(status.progress() * 100))

      print ("Your sharable link: "+ "https://drive.google.com/file/d/" + file.get('id')+'/view')


      When I run my script I get:



          status, response = prem.next_chunk()
      File "/usr/local/lib/python3.5/dist-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
      return wrapped(*args, **kwargs)
      File "/usr/local/lib/python3.5/dist-packages/googleapiclient/http.py", line 899, in next_chunk
      if self.resumable.size() is None:
      AttributeError: 'NoneType' object has no attribute 'size'


      I use api v2 and python 3.5







      python google-drive-sdk






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 19:12









      BardulfBardulf

      178




      178
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You need to monitor the progress of uploading the file, not setting the permissions:



          media_body = MediaFileUpload(file_name, resumable=True)
          body = {
          'title': file_name,
          'description': 'Uploaded By Bardulf'}
          file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink')

          response = None
          while response is None:
          status, response = file.next_chunk()
          if status:
          print ("Uploaded %d%%." % int(status.progress() * 100))

          if file:
          print(file_name + " uploaded successfully")
          prem = DRIVE.permissions().insert( fileId=response.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True})

          print ("Your sharable link: "+ "https://drive.google.com/file/d/" + response.get('id')+'/view')


          And you also need to remove that stray execute() when you are using resumable media.






          share|improve this answer


























          • When I try, I get AttributeError: 'dict' object has no attribute 'next_chunk'

            – Bardulf
            Nov 24 '18 at 9:36











          • @Bardulf sorry my bad, you also need to remove the stray .execute() when you are using resumable media. I've edited my answer.

            – Rob Bricheno
            Nov 24 '18 at 13:36











          • I change it, and I get error on prem it show AttributeError: 'HttpRequest' object has no attribute 'get'

            – Bardulf
            Nov 24 '18 at 14:07











          • @Bardulf edited again, the response is like the result of .insert(...).execute() so use that to get the ID. Third time's the charm?

            – Rob Bricheno
            Nov 24 '18 at 14:29











          • It's working well.

            – Bardulf
            Nov 24 '18 at 14:51












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451904%2fadd-upload-progress-to-google-drive-script-using-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You need to monitor the progress of uploading the file, not setting the permissions:



          media_body = MediaFileUpload(file_name, resumable=True)
          body = {
          'title': file_name,
          'description': 'Uploaded By Bardulf'}
          file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink')

          response = None
          while response is None:
          status, response = file.next_chunk()
          if status:
          print ("Uploaded %d%%." % int(status.progress() * 100))

          if file:
          print(file_name + " uploaded successfully")
          prem = DRIVE.permissions().insert( fileId=response.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True})

          print ("Your sharable link: "+ "https://drive.google.com/file/d/" + response.get('id')+'/view')


          And you also need to remove that stray execute() when you are using resumable media.






          share|improve this answer


























          • When I try, I get AttributeError: 'dict' object has no attribute 'next_chunk'

            – Bardulf
            Nov 24 '18 at 9:36











          • @Bardulf sorry my bad, you also need to remove the stray .execute() when you are using resumable media. I've edited my answer.

            – Rob Bricheno
            Nov 24 '18 at 13:36











          • I change it, and I get error on prem it show AttributeError: 'HttpRequest' object has no attribute 'get'

            – Bardulf
            Nov 24 '18 at 14:07











          • @Bardulf edited again, the response is like the result of .insert(...).execute() so use that to get the ID. Third time's the charm?

            – Rob Bricheno
            Nov 24 '18 at 14:29











          • It's working well.

            – Bardulf
            Nov 24 '18 at 14:51
















          1














          You need to monitor the progress of uploading the file, not setting the permissions:



          media_body = MediaFileUpload(file_name, resumable=True)
          body = {
          'title': file_name,
          'description': 'Uploaded By Bardulf'}
          file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink')

          response = None
          while response is None:
          status, response = file.next_chunk()
          if status:
          print ("Uploaded %d%%." % int(status.progress() * 100))

          if file:
          print(file_name + " uploaded successfully")
          prem = DRIVE.permissions().insert( fileId=response.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True})

          print ("Your sharable link: "+ "https://drive.google.com/file/d/" + response.get('id')+'/view')


          And you also need to remove that stray execute() when you are using resumable media.






          share|improve this answer


























          • When I try, I get AttributeError: 'dict' object has no attribute 'next_chunk'

            – Bardulf
            Nov 24 '18 at 9:36











          • @Bardulf sorry my bad, you also need to remove the stray .execute() when you are using resumable media. I've edited my answer.

            – Rob Bricheno
            Nov 24 '18 at 13:36











          • I change it, and I get error on prem it show AttributeError: 'HttpRequest' object has no attribute 'get'

            – Bardulf
            Nov 24 '18 at 14:07











          • @Bardulf edited again, the response is like the result of .insert(...).execute() so use that to get the ID. Third time's the charm?

            – Rob Bricheno
            Nov 24 '18 at 14:29











          • It's working well.

            – Bardulf
            Nov 24 '18 at 14:51














          1












          1








          1







          You need to monitor the progress of uploading the file, not setting the permissions:



          media_body = MediaFileUpload(file_name, resumable=True)
          body = {
          'title': file_name,
          'description': 'Uploaded By Bardulf'}
          file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink')

          response = None
          while response is None:
          status, response = file.next_chunk()
          if status:
          print ("Uploaded %d%%." % int(status.progress() * 100))

          if file:
          print(file_name + " uploaded successfully")
          prem = DRIVE.permissions().insert( fileId=response.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True})

          print ("Your sharable link: "+ "https://drive.google.com/file/d/" + response.get('id')+'/view')


          And you also need to remove that stray execute() when you are using resumable media.






          share|improve this answer















          You need to monitor the progress of uploading the file, not setting the permissions:



          media_body = MediaFileUpload(file_name, resumable=True)
          body = {
          'title': file_name,
          'description': 'Uploaded By Bardulf'}
          file = DRIVE.files().insert( body=body, media_body=media_body, fields='id, alternateLink')

          response = None
          while response is None:
          status, response = file.next_chunk()
          if status:
          print ("Uploaded %d%%." % int(status.progress() * 100))

          if file:
          print(file_name + " uploaded successfully")
          prem = DRIVE.permissions().insert( fileId=response.get('id'), body={'type': 'anyone', 'value': 'anyone', 'role': 'reader', 'withLink': True})

          print ("Your sharable link: "+ "https://drive.google.com/file/d/" + response.get('id')+'/view')


          And you also need to remove that stray execute() when you are using resumable media.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 24 '18 at 14:28

























          answered Nov 23 '18 at 21:40









          Rob BrichenoRob Bricheno

          2,489420




          2,489420













          • When I try, I get AttributeError: 'dict' object has no attribute 'next_chunk'

            – Bardulf
            Nov 24 '18 at 9:36











          • @Bardulf sorry my bad, you also need to remove the stray .execute() when you are using resumable media. I've edited my answer.

            – Rob Bricheno
            Nov 24 '18 at 13:36











          • I change it, and I get error on prem it show AttributeError: 'HttpRequest' object has no attribute 'get'

            – Bardulf
            Nov 24 '18 at 14:07











          • @Bardulf edited again, the response is like the result of .insert(...).execute() so use that to get the ID. Third time's the charm?

            – Rob Bricheno
            Nov 24 '18 at 14:29











          • It's working well.

            – Bardulf
            Nov 24 '18 at 14:51



















          • When I try, I get AttributeError: 'dict' object has no attribute 'next_chunk'

            – Bardulf
            Nov 24 '18 at 9:36











          • @Bardulf sorry my bad, you also need to remove the stray .execute() when you are using resumable media. I've edited my answer.

            – Rob Bricheno
            Nov 24 '18 at 13:36











          • I change it, and I get error on prem it show AttributeError: 'HttpRequest' object has no attribute 'get'

            – Bardulf
            Nov 24 '18 at 14:07











          • @Bardulf edited again, the response is like the result of .insert(...).execute() so use that to get the ID. Third time's the charm?

            – Rob Bricheno
            Nov 24 '18 at 14:29











          • It's working well.

            – Bardulf
            Nov 24 '18 at 14:51

















          When I try, I get AttributeError: 'dict' object has no attribute 'next_chunk'

          – Bardulf
          Nov 24 '18 at 9:36





          When I try, I get AttributeError: 'dict' object has no attribute 'next_chunk'

          – Bardulf
          Nov 24 '18 at 9:36













          @Bardulf sorry my bad, you also need to remove the stray .execute() when you are using resumable media. I've edited my answer.

          – Rob Bricheno
          Nov 24 '18 at 13:36





          @Bardulf sorry my bad, you also need to remove the stray .execute() when you are using resumable media. I've edited my answer.

          – Rob Bricheno
          Nov 24 '18 at 13:36













          I change it, and I get error on prem it show AttributeError: 'HttpRequest' object has no attribute 'get'

          – Bardulf
          Nov 24 '18 at 14:07





          I change it, and I get error on prem it show AttributeError: 'HttpRequest' object has no attribute 'get'

          – Bardulf
          Nov 24 '18 at 14:07













          @Bardulf edited again, the response is like the result of .insert(...).execute() so use that to get the ID. Third time's the charm?

          – Rob Bricheno
          Nov 24 '18 at 14:29





          @Bardulf edited again, the response is like the result of .insert(...).execute() so use that to get the ID. Third time's the charm?

          – Rob Bricheno
          Nov 24 '18 at 14:29













          It's working well.

          – Bardulf
          Nov 24 '18 at 14:51





          It's working well.

          – Bardulf
          Nov 24 '18 at 14:51




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451904%2fadd-upload-progress-to-google-drive-script-using-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini