Hi,
I am trying to use the graphic API to upload images (it is a large number so it is easier to use the API rather than upload them via the browser).
I managed to upload them but I want to divide them into folders, which does not seem to work. Here is my code:
headers = {"x-api-token": apiToken }
files = {'file' : (path, open(path, 'rb'), 'image/jpeg'),"folder": graphic_folder}
baseUrl = "https://{0}.qualtrics.com/API/v3/libraries/{1}/graphics/".format(dataCenter,graphic_library_id)
response = requests.post(baseUrl, files=files,headers=headers)
the images get uploaded but they are in the "uncategorized" folder, not the graphic_folder I specified.
Could someone please help me with that? Thanks a lot.
What solves this for me was to use this line of code to define files instead of yours:
files = {'file' : (graphic_name, open(graphic_path, 'rb'), graphic_type), "folder": (None,foldername)}
where graphic_name, graphic_path, graphic_type are the same parameters defined by you, and foldername is the string you want to name the destination folder on Qualtrics
I'm trying to upload an image from my local machine to the Qualtrics library. The cURL works fine, but the python request does not. Can anyone tell me the cause of the issue?
The CURL code
curl --request POST \\
--url https://iad1.qualtrics.com/API/v3/libraries/libraryID/graphics \\
--header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \\
--header 'X-API-TOKEN: tokenID' \\
--form file=@/Users/username/Desktop/pic_1.png \\
--form folder=foldername
The python code
conn = http.client.HTTPSConnection("iad1.qualtrics.com")
payload = "-----011000010111000001101001\\r\\nContent-Disposition: form-data; name=\\"name\\"\\r\\n\\r\\npic1.png\\r\\n-----011000010111000001101001\\r\\nContent-Disposition: form-data; name=\\"file\\"\\r\\n\\r\\n@/Users/username/Desktop/pic_1.png\\r\\n-----011000010111000001101001\\r\\nContent-Disposition: form-data; name=\\"contentType\\"\\r\\n\\r\\nimage/png\\r\\n-----011000010111000001101001\\r\\nContent-Disposition: form-data; name=\\"folder\\"\\r\\n\\r\\nfoldername\\r\\n-----011000010111000001101001--\\r\\n\\r\\n"
headers = {
'Content-Type': "multipart/form-data; boundary=---011000010111000001101001",
'X-API-TOKEN': "tokenID"
}
conn.request("POST", "/API/v3/libraries/libraryID/graphics", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
The error message with the python code is
{"meta":{"httpStatus":"400 - Bad Request","error":{"errorMessage":"Missing Content-Type for file part. name=file","errorCode":"MFDP_3"},"requestId":"7a009aca-135f-49bc-b755-6ccfe8b5da1d"}}
but it seems I have specified content-type in the payload.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.