Uploading Image to a ticket | Community
Skip to main content

Uploading Image to a ticket

  • March 22, 2021
  • 11 replies
  • 0 views

Hi,

I'm trying to upload an image to a ticket, taken from a HTML5 upload input. I successfully get a return from the API call but the image is always a blank 16*16.

 

        $image = $_FILES['image']['name'];
        $imageTmp = $_FILES['image']['tmp_name'];
        $uploadImage = json_decode(shell_exec("curl https://subdomain.zendesk.com/api/v2/uploads?filename=$image \
        -data-binary @/$imageTmp/$image  \
        -v -u username:password \
        -H \"Content-type: multipart/form-data\" \
        -X POST"), true);
All sensitive information has been removed.
 
Let me know what I'm doing wrong please! 

 

 

11 replies

Greg29
  • March 22, 2021

Hi Cameron! Could you try changing your "Content-type" to "application/binary" instead and see if that resolves it for you? I'm referencing from our API docs here and I believe I've seen this resolve this issue in the past, but if not, we can dig in a bit further.


  • Author
  • March 22, 2021

@Greg - Community Manager 

Thanks for the quick reply. Unfortunately that didn't fix the issue.

I have also tried a few different variations of -data-binary, using the following also doesn't fix the issue

        $uploadImage = json_decode(shell_exec("curl https://removed.zendesk.com/api/v2/uploads?filename=$image \
        -data-binary @$imageTmp  \
        -v -u user:pass \
        -H \"Content-type: application/binary\" \
        -X POST"), true);

Greg29
  • March 22, 2021

Thanks for the update...two things that I want to check:

  • Could you try a direct cURL call to see if that works? Just to eliminate anything funky going on with the underlying script.
  • Is this a .dat file or are you uploading directly as a .png/.jpg? If it is a direct image, make sure that you change the content type associated with that file (image/png or image/jpeg).

  • Author
  • March 22, 2021

@Greg - Community Manager

Hi Greg,

I had just tried both of those suggestions, so I navigated into the directory of a PNG image and tried this command straight in the command line. I got no errors, and got returned data again (token, attachment url etc)

Unfortunately it still doesn't work, despite giving me a URL to access the image (it's still 16x16 and just a white square)

curl "https://removed.zendesk.com/api/v2/uploads?filename=tag.png" -data-binary@tag.png -v -u removed:password -H "Content-Type:image/png" -X POST

Greg29
  • March 22, 2021

Just a shot in the dark here...what is the file size of the image you're trying to upload?

Greg Katechis | Developer Support and Enablement Engineer


  • Author
  • March 22, 2021

@Greg - Community Manager

Just 16kb.


Greg29
  • March 22, 2021

Thanks for checking, figured that wasn't going to be it. Could you check to see if you're uploading it in base64? If you are, please change that to binary and try again by converting it to a blob and seeing if that works?

Greg Katechis | Developer Support and Enablement Engineer


Felipe25
  • January 11, 2022

I'm having the same problem. How can I convert to a blob to try to upload?


Eric27
  • January 11, 2022
Hi Felipe,

Can you provide a code snippet of your request? This will help us to troubleshoot more effectively.

Thanks!

  • February 17, 2022

Hi ! 

Not sure to understand whether it's possible to upload base64 files (images) ?


Eric27
  • February 17, 2022

Hey there,

You'll need to use a generic binary format e.g. `application/binary`.

Thanks!