I am using the code below to try to upload a file to my girder instance using python3. I keep getting a response code saying “Chunk is smaller than the minimum size.” which implies that the data is not being read by Girder. The API documentation says: “The data for the chunk should be sent as the body of the request using an appropriate content-type and with the other parameters as part of the query string.” What is the proper way to make this work?
def read_in_chunks(file_object, chunk_size=1024): while True: data = file_object.read(chunk_size) if not data: break yield data response = requests.post( url = serverAddress + 'api/v1/file', params = {'parentId': parentId, 'name': name, 'parentType': parentType, 'size': filesize, 'mimeType': 'application/octet-stream'}, headers = {'Girder-Token': accessToken} ) uploadid = response.json()['_id'] chunk_size= 1024 offset = 0 with open(path, 'rb') as filehandle: for piece in read_in_chunks(filehandle, chunk_size=chunk_size): response = requests.post( url = serverAddress + 'api/v1/file/chunk', params = {'uploadId': uploadid, 'offset': offset}, headers = {'Girder-Token': accessToken}, data = piece ) offset += chunk_size