Add photos to an existing photo album. Valid for Communifire version 6.0 and above.
POST https://myintranet.communifire.com/api/albums/381/photos
Photo JSON object is returned as ResponseData.
{ "IsError": false, "ResponseData": [ { "ContentID": 388, "EntityType": 6, "ContentTypeID": 6, "ContentTitle": "Introduction", "ContentStub": "Introduction", "ContentBody": "", "ContentBodyUnprocessed": "", "ContentSummary": "", "AuthorID": 65, "AuthorUserName": "aparna", "UpdatedByUserID": 65, "UpdatedByUserDisplayName": "Aparna Anand", "UpdatedByUserUsername": "aparna", "UpdatedByUserEmail": "aparna@axerosolutions.com", "UpdatedByUserFirstName": "Aparna", "UpdatedByUserLastName": "Anand", "UpdatedByUserAvatarImageUrl": "https://your-community.com/assets/Themes/default/images/avatar-default.jpg", "UpdatedByUserProfileUrl": "https://your-community.com/people/aparna", "ParentContentID": 381, "ContentVersionID": 1, "SpaceID": 15, "WorkflowID": 0, "CurrentWorkflowStepID": 0, "StatusID": 1, "DateCreated": "2019-03-27T16:56:47.317", "DateUpdated": "2019-03-27T16:56:47.317", "IsFeatured": false, "ViewCount": 0, "CommentCount": 0, "Rating": 0, "MetaTitle": "Introduction", "MetaDescription": "", "MetaKeywords": "", "ContentFeaturedImage": "abbd8da0-2a9c-456d-b7fd-4f14d443af4b.jpeg", "ContentThumbImage": "abbd8da0-2a9c-456d-b7fd-4f14d443af4b.jpeg", "ContentFeaturedImageFullURL": "https://your-community.com/Assets/Uploaded-Photos/65/381/e54b922c-900a-4d9a-a516-31783ce2c2c8.jpeg", "ContentThumbImageFullURL": "https://your-community.com/Assets/Uploaded-Photos/65/381/abbd8da0-2a9c-456d-b7fd-4f14d443af4b.jpeg", "PageH1Content": "", "HeadCustomContent": "", "SideBarContent": "", "ExtraSideBarContent": "", "ContentMediaServerID": 1, "ContentMediaFileName": "e54b922c-900a-4d9a-a516-31783ce2c2c8.jpeg", "ContentMediaServerRootURL": "https://your-community.com/Assets/Uploaded-Photos", "SpaceName": "Communication", "SpaceURL": "https://your-community.com/spaces/15/Communication", "AuthorDisplayName": "Aparna Anand", "AuthorEmail": "aparna@axerosolutions.com", "AuthorFirstName": "Aparna", "AuthorLastName": "Anand", "AuthorAvatarImageUrl": "https://your-community.com/assets/Themes/default/images/avatar-default.jpg", "AuthorProfileUrl": "https://your-community.com/people/aparna", "IsLatest": false, "TagsCSV": "", "DateCreatedString": "3/27/2019 10:26 PM", "DateCreatedShortString": "3/27/2019", "DatePublishedString": "", "DatePublishedShortString": "", "DateUpdatedString": "3/27/2019 10:26 PM", "DateUpdatedShortString": "3/27/2019", "ContentURL": "https://your-community.com/spaces/15/Communication/photo/aparna/album/388", "ContentVersionURL": "", "IsPublishedFromDraftMode": false, "IsPublishedFromDelayedPublishingMode": false, "ParentContentTitle": "album", "IsPublishedFromUnderProcessingMode": false, "IsWallContent": false, "HasRead": false, "ContentFileSize": 89123, "ContentFileSizeString": "87KB", "ContentTypeIconCSSClass": "icon-picture", "IsEditable": false, "IsDeletable": false, "IsDownloadable": false, "IsChekoutable": false, "IsUndochekoutable": false, "IsChekinable": false, "IsRestoreable": false, "IsPurgeable": false, "IsHistoryViewable": false, "IsMoveable": false, "ContentMediaOnlineViewUrl": "", "ContentMediaUrl": "https://your-community.com/Assets/Uploaded-Photos/65/381/e54b922c-900a-4d9a-a516-31783ce2c2c8.jpeg", "ContentHistoryUrl": "", "GoogleDocsEditUrl": "javascript:PopupCenter('/AjaxTemplates/GoogleDocsFile.aspx?cid=388&vid=1','Google Docs',800,600)", "ViewerVote": 0, "VoteCount": 0, "IsDirectory": false, "IsActivityStreamAlbum": false, "LastChildAuthorUserID": 0, "LastGrandChildAuthorUserID": 0, "TotalChildRecords": 0, "TotalGrandChildRecords": 0, "IsSticky": false, "IsAnswered": false, "ParentContentStub": "album", "AuthorRankImageUrl": "https://your-community.com/Assets/Uploaded-Photos/rank-lurker.gif", "AuthorRankName": "Lurker", "IsContentAvailablePostExpiry": false, "ContentIDCode": "gxBimFCbFXrditGvG0oXfQ%3D%3D", "TenantID": 1 } ], }
Please Note The content type that you pass in the header of your request should be multipart/form-data. You can attach multiple photos with this request.
Caller code:
string _cfBaseURL = "https://yourdomain.....communifire.com"; string _apiKey = "YWRtaW46N...............2E5ODhl"; // Required params int albumID = 12055; string filePath = @"C:\inetpub\......onedrive-2.png"; string fileName = "onedrive-2.png"; string apiEndPoint = "/api/albums/" + albumID + "/photos"; var response = HttpPostMultiPartFileStream<int>(apiEndPoint, filePath, fileName);
public T HttpPostMultiPartFileStream<T>(string requestURL, string filePath, string fileName) { string content = null; using (MultipartFormDataContent form = new MultipartFormDataContent()) { StreamContent streamContent; using (var fileStream = new FileStream(filePath, FileMode.Open)) { streamContent = new StreamContent(fileStream); streamContent.Headers.Add("Content-Type", "application/octet-stream"); streamContent.Headers.Add("Content-Disposition", string.Format("form-data; name=\"file\"; filename=\"{0}\"", fileName)); form.Add(streamContent, "file", fileName); using (HttpClient client = GetAuthenticatedHttpClient()) { HttpResponseMessage response = client.PostAsync(requestURL, form).GetAwaiter().GetResult(); content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); try { return JsonConvert.DeserializeObject<T>(content); } catch (Exception ex) { // Log the exception } return default(T); } } } }
GetAuthenticatedHttpClient code:
private HttpClient GetAuthenticatedHttpClient() { HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(_cfBaseURL); httpClient.DefaultRequestHeaders.Add("Rest-Api-Key", _apiKey); return httpClient; }
Async way:
using Newtonsoft.Json; using System; using System.IO; using System.Net.Http; using System.Threading.Tasks; namespace ConsoleApp { class Program { static string baseURL = "https://YOUR.communifire.com"; static string token = "YOUR_TOKEN"; static async Task Main(string[] args) { try { int albumID = YOURALBUMID; string requestedURL = $"api/albums/{albumID}/photos"; string filePath = "D:\\logo.jpg"; string fileName = "logo.jpg"; await HttpPostMultiPartFileStream<int>(requestedURL, filePath, fileName); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); } public static async Task<T> HttpPostMultiPartFileStream<T>(string requestURL, string filePath, string fileName) { string content = null; using (MultipartFormDataContent form = new MultipartFormDataContent()) { StreamContent streamContent; using (var fileStream = new FileStream(filePath, FileMode.Open)) { streamContent = new StreamContent(fileStream); streamContent.Headers.Add("Content-Type", "application/octet-stream"); streamContent.Headers.Add("Content-Disposition", string.Format("form-data; name=\"file\"; filename=\"{0}\"", fileName)); form.Add(streamContent, "file", fileName); using (HttpClient client = GetAuthenticatedHttpClient(baseURL, token)) { using (HttpResponseMessage response = await client.PostAsync(requestURL, form)) { content = await response.Content.ReadAsStringAsync(); } try { return JsonConvert.DeserializeObject<T>(content); } catch (Exception ex) { // Log the exception } return default(T); } } } } private static HttpClient GetAuthenticatedHttpClient(string baseURL, string token) { HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(baseURL); httpClient.DefaultRequestHeaders.Add("Rest-Api-Key", token); return httpClient; } } }
is requesting access to a wiki that you have locked: https://my.axerosolutions.com/spaces/5/communifire-documentation/wiki/view/31068/rest-api-add-photos
Your session has expired. You are being logged out.