title: Patch Request File Upload
body: <p>I have a REST API that I am trying to upload data to , which is basically this : <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update</a></p>
  
  <p>Now, since the only option I have is PATCH, what are the options for me to have an optimized data load. I have been able to upload files by using the data parameter and using the read() function, but I don't think it's optimal as the entire file is read into memory I guess. I have tried using the files parameter (the multipaprt form encoding) and also looked at the toolbelt package but that does not seem to work for PATCH</p>
  
  <p>This is the Sample Code that works but is not optimal </p>
  
  <pre><code>files={'file':('Sample',open('D:/FilePath/Demo.txt','rb'))}
  length=os.stat('D:/FilePath/Demo.txt')
  filesize=str(length.st_size)
  
  with open('D:/File|Path/Demo.txt','rb') as f:
      file_data = f.read()
  
  leng=len(file_data)
  
  header = {
  'Authorization': "Bearer " + auth_t
  }
  
  header_append = {
  'Content-Length': filesize,
  'Authorization': "Bearer " + auth_t
  #'If-None-Match': "*" #Conditional HTTP Header
  }
  
  header_flush = {
  'Content-Length': '0',
  'Authorization': "Bearer " + auth_t
  }
  
  
  header_read = {
  'Authorization': "Bearer " + auth_t
  }
  
  try:
      init_put=requests.put('https://adlstorageacc.dfs.core.windows.net/adobe/2019/02/DemoStreamFile4.txt?resource=file&amp;recursive=True', headers=header_flush, proxies=proxies,verify=False)
      init_write=requests.patch('https://adlstorageacc.dfs.core.windows.net/adobe/2019/02/DemoStreamFile4.txt?action=append&amp;position=0', headers=header_append, proxies=proxies,verify=False,data=file_data)
  
      flush_url='https://adlstorageacc.dfs.core.windows.net/adobe/2019/02/DemoStreamFile4.txt?action=flush&amp;position=' + str(leng)
      init_flush=requests.patch(flush_url, headers=header_flush, proxies=proxies,verify=False)
  </code></pre>
  
  <p>Problem is the line   </p>
  
  <pre><code>init_write=requests.patch('https://adlstorageacc.dfs.core.windows.net/adobe/2019/02/DemoStreamFile4.txt?action=append&amp;position=0', headers=header_append, proxies=proxies,verify=False,data=file_data)
  </code></pre>
  
  <p>It only seems to take take the data parameter. If I change it to </p>
  
  <pre><code>init_write=requests.patch('https://adlstorageacc.dfs.core.windows.net/adobe/2019/02/DemoStreamFile4.txt?action=append&amp;position=0', headers=header_append, proxies=proxies,verify=False,file=files)
  </code></pre>
  
  <p>I get an empty file.</p>
  
  <p>Same is the case when I use the requestToolbelt package.</p>
  
  <p>Does patch not recognize the file parameter? Nothing on the requests documents says any of it.</p>
  
  <p>Also, if data parameter is the only way out, what is the best way to loading a file without doing a f.read() or iteratively specifying number of characters to read using f.read(n). Isn't there a better way?</p>