AddImageToCell in smartsheet-csharp-sdk always throws an exception
Hello developers,
I am currently working on integrating Smartsheet API into my application and have encountered an issue related to image uploads using the Smartsheet SDK.
The specific error message I'm encountering is: "Only images can be uploaded. Please use a file of type jpg, gif, or png." I have already ensured that the content type is set to "image/jpeg," and the file being uploaded is indeed a valid JPEG image.
Here is the code:
public void AddImageToCell(long rowId, string columnName, string altText, string imageURL) { string tempFilePath = DownloadImage(imageURL); try { long columnId = (long)GetColumnIdByName(columnName); string contentType = "image/jpg"; RowColumnResources rowColumnResources = _smartsheetClient.SheetResources.RowResources.CellResources; rowColumnResources.AddImageToCell(_sheetID, rowId, columnId, tempFilePath, contentType, true, altText); } catch(Exception ex) { throw ex; } finally { if (File.Exists(tempFilePath)) { File.Delete(tempFilePath); } } }
---------------------------------------------------------------------------------------------
private string DownloadImage(string imageUrl) { string tempFileName = "temp_image.jpg"; using (var client = new WebClient()) { client.DownloadFile(imageUrl, tempFileName); } return tempFileName; }
It was working in the older versions but in the latest one it is not.
Answers
-
Hi @sree_bharath,
Having looked at the SDK help at the URL shown below, it seems as though the line
string contentType = "image/jpg"
would need to be as follows
string contentType = "image"
It has been a while since I worked on c# code, so I apologies if I have misinterpreted this.
https://smartsheet.redoc.ly/tag/cellImages#operation/addImageToCell
Hope this helps!
John
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 64.1K Get Help
- 414 Global Discussions
- 221 Industry Talk
- 461 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 141 Just for fun
- 58 Community Job Board
- 462 Show & Tell
- 32 Member Spotlight
- 1 SmartStories
- 299 Events
- 38 Webinars
- 7.3K Forum Archives