OneDrive / onedrive-sdk-csharp

OneDrive SDK for C#! https://dev.onedrive.com
Other
294 stars 143 forks source link

Add support for square thumbnails #207

Closed tipa closed 7 years ago

tipa commented 7 years ago

Currently, square thumbnails like "smallSquare" are not supported. Probably custom sized thumbnails could be somehow supported too...

Ref: https://dev.onedrive.com/items/thumbnails.htm#size-values https://dev.onedrive.com/items/thumbnails.htm#custom-thumbnail-sizes

daboxu commented 7 years ago

hi @tipa , current the smallSquare thumbnail does return if you specify select it explicitly and there are some efforts needed:

build you request like

    var size = "smallSquare";
    var expandString = string.Format("thumbnails(select={0})",size);
    var item = await this.oneDriveClient.Drive.Items[id].Request().Expand(expandString).GetAsync();

   // parse the thumbnail
   var thumbnailSet = item.Thumbnails.CurrentPage.FirstOrDefault(set => set.AdditionalData?[size] != null);
   if (thumbnailSet != null)
   {
       var serializer = new Serializer();
       var thumbnail = serializer.DeserializeObject<Thumbnail>(thumbnailSet.AdditionalData[size].ToString());
   }

this should also work if you want to select customized thumbnails, please let me know if it works.

tipa commented 7 years ago

I have come to a different solution via url parameters: ?width=80&height=80&cropmode=center

daboxu commented 7 years ago

cool, good to know that.

toby11 commented 1 year ago

@tipa how did you acheive passing in custom url parameters using the onedrive sdk?