I want to uploadd file to comment from API

hi,
I want to upload the file to the comment from API. but I am getting an Internal server error.
below is my mution code and screen shot.

I have even tried for

still getting the “internal server error”. also can’t understand what is “var boundary = “xxxxxxxxxx”;”

need your help…
thanks in advance

mutation ($file: File!) {
add_file_to_update (update_id: 808129739, file: $file)
{
id
}
}
Please see the image.

Hey @mamun,

Could you please try sending the POST request to our API URL, rather than one with your slug?

https://api.monday.com/v2/file/

-Daniel

Hi Dsilva,
Thank you for your reply. actually I found that my code was working for txt/rar/zip file type not for Image files.

I am using the following code. get some luck when using Ngrok as my server (Local computer).
I am able to upload almost any kind of file. but when I push my code to Azure (Linux) server. I can not able to upload jpg file. but if I make it zip/rar the file is getting uploaded properly. when trying to upload jpg/png or any image file it shows me
{message":{“error_message”:“Internal server error”,“status_code”:500}}

can’t find any clue can any one tell me why the following code is not working on azure (Linux) server. while it is working from my computer (Winows 10, NGROK)

const url = " https://api.monday.com/v2/file/";
const content = await fsPro.readFile(upfile, “binary”);

  // construct query part

  data += "--" + boundary + "\r\n";

  data += "Content-Disposition: form-data; name=\"query\"; \r\n";

  data += "Content-Type:application/json\r\n\r\n";

  data += "\r\n" + query + "\r\n";



  // construct file part

  data += "--" + boundary + "\r\n";

  data += "Content-Disposition: form-data; name=\"variables[file]\"; filename=\"" + upfile + "\"\r\n";

  data += "Content-Type:application/octet-stream\r\n\r\n";



  var payload = Buffer.concat([

    Buffer.from(data, "utf8"),

    new Buffer.from(content, 'binary'),

    Buffer.from("\r\n--" + boundary + "--\r\n", "utf8"),

  ]);



  // construct request options

  var options = {

    method: 'post',

    headers: {

      "Content-Type": "multipart/form-data; boundary=" + boundary,

      "Authorization": API_TOKEN

    },

    body: payload,

  };

const response = await fetch(url, options) // , body: data

@dsilva,
May I get some help from you on this. can’t find any reason why the same code will not work on 2 different servers.

Hey @mamun - apologies for the delay on this.

Could you let me know the file size of the image you’re trying to upload? I’m wondering if perhaps there might be some limit to this.

The other option that came to mind was to use something like CURL to upload the files - it’s something personally I’ve found a bit easier to parse through:

curl --location --request POST 'https://api.monday.com/v2/file/' \

--header 'Authorization: xxxxx' \

--form 'query=mutation ($file: File!) {

add_file_to_update (file: $file, update_id: xxxxxx) {

id

}

}' \

--form 'variables[file]=@/Users/danny/Downloads/screenshot.jpg'

-Daniel