I am trying to upload files to link to support tickets. Because of CORS issues, I am not able to make the request from the browser and am sending the base64 encoded file string to the backend with graphql. Using python requests and the v3 files API I am not able to send the file. I always get either a 41 5 or a 400 with no context.
I have tried using the files argument, data, json with the base64 string, multipart/form-data as the ContentType.
@m1Viss - yes, I think you have put your finger on an issue of workflow step code that is underwhelmingly documented and without really good examples. The assumption of these API calls seems to be that the code is running on some local desktop context - when you try and translate that to the HubSpot custom code workflow environment the handling of file upload/import is a lot tricker.
In most of my experience, I have been able to load the file data into a byte array like yours from a URL link or similar. But having read the bytes it is necessary to set the 'encoding' value of the response data structure to enable the right interprettation of the data. This is where I have come unstuck in the past, and perhaps where you are having problems as well.
For example - this seems to work for text file handling:
# get text file content
response = requests.request("GET", text_url, headers=headers)
response.encoding = 'utf-8' # fix for this type of file
pdf_text = response.text
When you have the extracted file data, then you can apply to the upload API through use of the files configuration JSON.
files_data = {
'fileName' : file_name, #make sure extension is set on name for type of data
'folderPath' : folder_name,
'file': file_string,
'charsetHunch': 'application/pdf', #or whatever is needed
'options': json.dumps(file_options)
}
Another stumbling block for me has been the header configuration of the upload API call, but it looks like you have that base covered.
Thank you for responding. Unfortunately, the addition of 'charsetHunch' hasn't changed the outcome. In my case I'm trying to upload a jpg and I attempted both 'image/jpeg' and 'image/jpeg;base64' (which is what the FileReader provides as data type). As I mentioned in the original ticket I have attempted sending the bytes and the bas64 string, and continue to get a 400 error with no context.
Have you successfully sent image files via this method? What requests arguments did you use in the post request (data, json, files, etc..)?