AnsweredAssumed Answered

Help to solve the error : Cannot upload a blob after already uploading via url

Question asked by Javier Machin on Jan 29, 2019
Latest reply on Jun 24, 2019 by

Hi, I need the help of the community to understand this error: 

      "<Response [500]> Cannot upload a blob after already uploading via url".


The link that I am following as reference: Submission Comments - Canvas LMS REST API Documentation 


That happened when I tried to upload a file as comment to the canvas.

import os

def upload_file(self, url):
    with open(url, 'rb') as f:
        file_content =
    return file_content
def upload_jn_to_canvas(self):
   # Step 1 - tell Canvas you want to upload a file
   post_api_url = '/api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id/comments/files'

   session = requests.Session()
   session.headers = {'Authorization': 'Bearer {0}'.format(self.token)}
   response =,
                            'name': name_file,
                            'size': os.path.getsize(jupyter_notebook_file),
                            'parent_folder_path': '/',
                            'content-type': 'binary/octet-stream'

   print('Session Headers: ', session.headers)
   print('Post URL: ', post_api_url)

   # Step 2 - upload file
   parameters = list(response.json()['upload_params'].items())
   parameters.append((u'file', self.upload_file(jupyter_notebook_file)))

   response2 =['upload_url'], files=parameters)