I am trying to implement a support request email in our app. I can upload attachments and send requests via cURL. Both work fine from the command line. And I have the app working to upload attachments and create requests that attach the uploads. However, although the attachments are formatted correctly when submitted via cURL, they are NOT when I submit them using the app. I tried using both a Dropzone and a simple form to grab the attachments. I also tried sending the file object and converting the file to base64 -- neither worked. Here is how I'm structuring the request:
Attachment uploads
Sending the file from the html form's input field:
const submitCustomerServiceAttachment = (file) => {
const url = 'https://onbeep.zendesk.com/api/v2/uploads.json?filename=' + file.name + '&token='
const headers = {
'Content-Type': 'application/binary'
}
const options = {
url,
method: 'POST',
headers: headers,
body: file
}
request(options, callback)
}
Or, using base64 (when I put base64 code into a decoder, I clearly get my image back, so it's converting it correctly -- and I have tried both with and without the preliminary text before the comma that gets returned by .readAsDataURL()):
const submitCustomerServiceAttachment = (file) => {
const reader = new FileReader()
reader.readAsDataURL(file)
const url = 'https://onbeep.zendesk.com/api/v2/uploads.json?filename=' + file.name + '&token='
const headers = {
'Content-Type': 'application/binary'
}
reader.onloadend = function() {
const fileInBinary = reader.result.split(',').slice(1).join();
const options = {
url,
method: 'POST',
headers: headers,
body: fileInBinary
}
request(options, callback)
}
}
I would appreciate any suggestions about how to format the data being sent or any other options to include! Thank you!!!
This topic has been closed for replies.
Login to the community
No account yet? Create an account
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.