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
- Customer Resources
- 64.8K Get Help
- 437 Global Discussions
- 138 Industry Talk
- 470 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 65 Community Job Board
- 486 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives