File upload SDK

Hey Everyone!

I’m sorry for making a duplicate of my old post, but this one is a bit different. ​

I found out that there’s now a SDK way of file upload rather than having an authentication flow which is what I have now. I was excited to implement it, so I updated the package to: "monday-sdk-js": "^0.1.2",
​but I ran into some issues.

When trying to upload a file with the sdk I get:

Error: Invalid content-type on response from monday api graphql
   ​at client.js:117
   ​at client.js:137
   ​at Array.forEach (<anonymous>)
   ​at MondayClientSdk._receiveMessage (client.js:135)

This is for the add_file_to_update mutation. The update ID is indeed an Integer and file is a file, but maybe the file isn’t set up properly for upload?

This is the file when I console log it:

{file: File, name: "uploaded-file", ext: ".png"}
ext: ".png"
file: File
lastModified: 1585754352396
lastModifiedDate: Wed Apr 01 2020 11:19:12 GMT-0400 (Eastern Daylight Time)
__proto__: Object
name: "donot1.png"
size: 2250079
type: "image/png"
webkitRelativePath: ""
__proto__: File
name: "uploaded-file"

My mutation is written like this:

   ​const fileMutation = `mutation add_file($update_id:Int!, $file: File!) {
           ​add_file_to_update(update_id: $update_id, file: $file) {
                   ​id
               ​}
           ​}
       ​`;

   ​const variables = { file, update_id: parseInt(updateID) };

   ​try {
     ​monday.api(fileMutation, { variables })
       ​.then((res) => {
         ​if (res) {
           ​console.log(res);
         ​}
       ​})
       ​.catch((err) => console.log(err));
   ​} catch (err) {
     ​console.log(err);
   ​}

I hope I’m not misunderstanding the new feature post as this feature was definitely needed for me. I currently have it working with a simple post request using the mutation using user’s token obtained from an auth flow. I would love to negate that extra step. I hope I can get someone to help me with this new awesome feature. Thank you in advance!

Hey @pepperaddict

Glad to see you try out this new feature, and I’m really sorry to hear you’ve been having some issues with it. I’d love to take a further look on my end and investigate this further with you to get to the bottom of this.

Just to make sure we’re on the same page here, does the file never get uploaded? It seems like the error occurs when the response from our API is received, is my understanding correct? Does this occur with any kind of file?

Also, to clarify further, are you sending this query from within your server, or from within a Board View/Widget?

Those will help us troubleshoot the behaviour a little further and hopefully resolve it :slight_smile:

-Alex

1 Like

Hello @AlexSavchuk !

Thank you for getting back to me on this!

I got it to work!!! It was the file setup that was the issue. I set it up for the back-end communication and completely forgot about it. Which is why when I console log the file, it was this:

{
file: the actual file, 
name: 'uploaded-file', 
ext: '.png'
}

My apologies! It was all my fault.

It is working flawlessly now and I’m loving it!!!

1 Like

I’m so glad to hear this is working well for you now, @pepperaddict :slight_smile: That’s amazing news and great job troubleshooting this.

-Alex

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.