What is the proper Content-Type string for an Excel (xlsx) file row attachment?
Hello, I have an Excel document (xlsx) that I want to upload to a row through the API. My code does successfully upload the file as a row attachment. However, when I download the file through Smartsheet and try to open it, I get an error "Excel cannot open the file 'file_name.xlsx' because the file format or file extension is not valid'. If I manually upload the original file myself to the Smartsheet row, and then download it, the downloaded file opens without error. I only get the error when I upload the file through the API. I'm using "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" as the Content-Type string. Is that not correct?
Best Answer
-
@Dan Britton @Brian_Richardson I have used octet-stream and there is also this one specific to excel:
application/vnd.ms-excel
Make sure your body is only the content stream, and it can't be base64 it has to be decoded.
Answers
-
The API docs have application/octet-stream as the Content-Type for uploading an attachment.
https://smartsheet.redoc.ly/tag/attachments#operation/attachments-attachToSheet
-
Thanks, but unfortunately changing the Content-Type to application/octet-stream did not solve the problem.
-
@Samuel Mueller have you successfully done any attachment uploads or have advice for @Dan Britton ?
-
@Dan Britton @Brian_Richardson I have used octet-stream and there is also this one specific to excel:
application/vnd.ms-excel
Make sure your body is only the content stream, and it can't be base64 it has to be decoded.
-
are you uploading this from an email or something? or power automate? what program are you using to attach the file?
-
@Samuel Mueller @Brian_Richardson Thanks, you both helped me determine that I'm barking up the wrong tree here with the Content-Type string. Now I know to look somewhere else for the problem. Much appreciated! To answer your question, I'm using the C# SDK to upload a local file as a row attachment.
-
@Dan Britton okay. I just have run into issues before where I am sending the wrong data mistakenly, like if it was from an email I was actually sending a logo as an 'excel', and then when I tried to open I got the error you are receiving. That's why I'm saying make sure you are sending the correct data in the body, only the data, and decoded from base64.
Good luck, let us know if there is anything else we can help with.
-
In case anyone finds this thread in a search, my problem with row attachments was solved by updating Visual Studio, installing .Net 8, and re-installing the latest Smartsheet C# SDK. My inaction on updating software was to blame.
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 63K Get Help
- 380 Global Discussions
- 212 Industry Talk
- 442 Announcements
- 4.6K Ideas & Feature Requests
- 140 Brandfolder
- 129 Just for fun
- 130 Community Job Board
- 449 Show & Tell
- 30 Member Spotlight
- 1 SmartStories
- 305 Events
- 34 Webinars
- 7.3K Forum Archives