I am trying to upload a file to ShareFile. In Postman, I am able to do it but in Python get 200 status code and "ERROR: REJECTED" response body.
Here's my code.
def upload_file(self, file: bytes, folder_id: str, file_name: str, etag: str, content_type: str):
url = f"{self.api_base_url}/sf/v3/Items({folder_id})/Upload2"
headers = self._get_headers()
# First, get URL for file upload
response = requests.post(url, headers=headers, json={
"FileName": file_name,
"Raw": True,
})
upload_url = response.json().get("ChunkUri")
headers = self._get_headers()
headers["Content-Type"] = content_type
response = requests.post(upload_url, headers=headers, data=file)
When getting the URL, FileSize
also has to be specified unless it's specified elsewhere.
# First, get URL for file upload
response = requests.post(url, headers=headers, json={
"FileName": file_name,
"Raw": True,
"FileSize": len(file),
})