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
- 62.1K Get Help
- 348 Global Discussions
- 199 Industry Talk
- 427 Announcements
- 4.4K Ideas & Feature Requests
- 133 Brandfolder
- 127 Just for fun
- 127 Community Job Board
- 455 Show & Tell
- 28 Member Spotlight
- 1 SmartStories
- 282 Events
- 36 Webinars
- 7.3K Forum Archives