I am attempting to upload a number of files using the v2 endpoint, but it seems to fail whenever the file type is a png. I get this response from the server:
Thanks for the replies. I think @basdebruin is correct. It seems that the Monday server is returning a error from the ImageMagick library whenever I attempt to upload a PNG file.
To expand a little bit, I am running a script that is transferring PNG files from one board to another. The workflow is:
Obtain the URL from the original board.
Download file
Upload file to new board
The file is being uploaded to a column. I don’t think it is a problem with my code, as pdf files work without issue. Unless there is something special we need to do with PNGs that I’m not aware of, I believe that the code should be the same regardless of file type. I also don’t think the PNG is malformed, as it was uploaded to the original board through the browser without issue. There seems to be a difference between the v2 file endpoint in the API, and the way the browser handles the file upload.
That doesn’t seem to help unfortunately… I think I’m going to need to see exactly what postman is doing differently when it constructs the multi-part request vs what my code is doing.
@Matias.Monday@basdebruin I just replicated the exact form data that is being output by postman in the request that succeeds, and my code is still failing. The only thing I can think of is that fss.createWriteStream and fs.readFile need a specific encoding other than the default. I tried a few, from base64 to binary, and none of them seem to work. Whatever it is, I’m fairly certain the problem has been narrowed down to how the file is being encoded.
It didn’t even occur to me to check the file size. The file size is 0. Which is confirmed by the fact that the pdf that was ‘successfully’ uploading, is in fact empty.
It also didn’t occur to me that the file endpoint that I am pulling from in the column, is only accessible if you are authenticated.
Now my question becomes, how do we provide authentication credentials for the download? I am running this script in a lambda function on AWS, so I was hoping to just pass an auth token in the header, but that doesn’t seem to work.
At least I’m heading in the right direction now I think. I spent way too much time tearing about my multipart request and rebuilding it different ways
@jmsmit38
Yeah, it is easy to overlook small thing. Authentication is dependent on what type of an app you are building. In don’t have Lamda experience as I run everything on NodeJS on my hosted VPS (under Plesk). If you are building an integration app you could use the shortLivedToken provided in every post monday makes to your endpoint. You need to decode that with your client secret and pass the token to the monday API calls. If you are building views I don’t think there is a need to do authentication as your app runs within the monday board environment. Hope this make sense.
@basdebruin
It’s actually just a script for data migration, thus there wouldn’t be a shortLivedToken since its not an integration app. I’m not sure either of your scenarios really apply to this. It’s really just a one off script that needs to run because we re-designed the architecture of our workspace and had to build new boards in a way where we couldn’t just send the items over to the new workspace with all of the data in place (I hope I’m making sense here… there were a lot of connected boards with data scattered across numerous items for every project). Is there an easier way to transfer the files from one board to another? It would be cool if since the file is already uploaded to Monday servers, you could just assign the URL to the cell, but their public API doesn’t have the ability to do that from what I can tell.
hi @jmsmit38
It would be very cool if you could just copy the assetID to another board / column but unfortunately that is not possible (yet?). I did try that and it looks like it is working (file is visible) but the file in the target location will not open.
If this is just a one time I would send a user token (admin perhaps) in the request. You can copy that token if you go to developers section in monday.
@basdebruin I got an access denied error with the user token, but I was able to find a workaround. I downloaded the file through the browser, copied the cookie string from the request, and pasted it into the request in my script. I also had to add a library called follow-redirects, because the endpoint that is returned from the file column is not the actual location of the file.
Do you know how long the session token cookie is valid for? And is there any way to obtain one from the user token?
hi @jmsmit38, I am wondering if you need to use a session token here. The user token should do it and does not expire. You have to set the user token in the Authorization header and I see you are setting it to:
"Authorization" : process.env.MONDAY_TOKEN
Does process.env.MONDAY_TOKEN contains the token found in My Tokens in the Developer environment?
That is correct. I tried both the API token and the User token and neither work here. The only way I found to do it was by setting the cookie string with the session token.
Im getting this error. {"errors":[{"message":"Variable file of type File! was provided invalid value","locations":[{"line":1,"column":19}],"value":null,"problems":[{"path":[],"explanation":"Expected value to not be null"}]}],"account_id":11771408}.
The whole process of fixing an HTTP error when uploading in WordPress can be solved by following five simple steps. Here’s what you need to do:
Step 1 Find Out If the HTTP Error is Temporary
Step 2 Rename Your Files
Step 3 Add Code to Modify WordPress Image Editors
Step 4 Deactivate Your Website Plugins
Step 5 Increase Your Server Memory