private List <Models.File> GetFilesByFolder(string token, string folderPath) { List <Models.File> files = null; if (!string.IsNullOrEmpty(folderPath)) { using (var dbx = new DropboxClient(token)) { var format = new ThumbnailFormat(); var size = new ThumbnailSize(); files = dbx.Files.ListFolderAsync(folderPath).Result.Entries .Where(f => f.IsFile == true) .Select(entry => new Models.File() { Name = entry.Name, Size = Decimal.Round(Convert.ToDecimal((entry.AsFile.Size / 1024f) / 1024f), 4), Type = entry.Name.Substring(entry.Name.LastIndexOf('.')).ToLower(), Id = entry.AsFile.Id, FilePath = entry.AsFile.PathLower //Thumbnail= Convert.ToBase64String(dbx.Files.GetThumbnailAsync(folderPath+"/"+entry.Name, format.AsJpeg, size.AsW64h64).Result.GetContentAsByteArrayAsync().Result) }) .ToList(); } } return(files); }
/// <summary> /// Gets the thumbnail of an image given its path /// </summary> /// <param name="path">The path to the picture</param> /// <param name="size">The size to return the thumbnail</param> /// <param name="format">The format to return the thumbnail as.</param> /// <returns></returns> public async Task <Stream> GetThumbnail(string path, ThumbnailSize size, ThumbnailFormat format) { path = FixPath(path); var queryParams = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("size", this.ThumbnailSizeString(size)), new KeyValuePair <string, string>("format", this.ThumbnailFormatString(format)) }; var response = await this._client.GetAsync(string.Format("{0}/{1}/thumbnails/{2}{3}{4}", ApiContentBaseUrl, Version, this.RootString, path, queryParams.ToQueryString( )) ); switch (response.StatusCode) { case HttpStatusCode.OK: break; case HttpStatusCode.NotFound: throw new CloudStorageItemNotFoundException( ); default: throw new HttpException((int)response.StatusCode, response.Content.ReadAsStringAsync( ).Result); } // Read response asynchronously as JsonValue and write out objects return(await response.Content.ReadAsStreamAsync( )); }
void Save() { var cfg = new ConfigNode("LOD_CONFIG"); var thumb = cfg.AddNode("Thumbnail"); thumb.AddValue("Enabled", ThumbnailEnabled.ToString()); thumb.AddValue("Width", ThumbnailWidth.ToString()); thumb.AddValue("Height", ThumbnailHeight.ToString()); thumb.AddValue("Format", ThumbnailFormat.ToString()); var ui = cfg.AddNode("ActivityInterface"); ui.AddValue("SecondsBeforeShowing", UI_DelayBeforeShowingActivityUI.TotalSeconds.ToInt().ToString()); ui.AddValue("SecondsBeforeHiding", UI_DelayBeforeHidingActivityUI.TotalSeconds.ToInt().ToString()); cfg.AddValue("TryUseToolbarForDebugUI", UI_TryUseToolbarForDebugUI.ToString()); cfg.AddValue("ShowDebugUI", UI_DisplayDebugUI.ToString()); cfg.AddValue("DontLoadEditorCatalogParts", Debug_DontLoadEditorCatalogThumbnailParts.ToString()); cfg.AddValue("CompressTextures", CompressTextures.ToString()); var cache = cfg.AddNode("Cache"); foreach (var el in CachedDataPerResUrl) { cache.AddNode(el.Value.ToConfigNode()); } cfg.Save(cfgFileLocation.FullName); IsDirty = false; }
/// <summary> /// <para>Get a thumbnail for a file.</para> /// </summary> /// <param name="resource">Information specifying which file to preview. This could be /// a path to a file, a shared link pointing to a file, or a shared link pointing to a /// folder, with a relative path.</param> /// <param name="format">The format for the thumbnail image, jpeg (default) or png. For /// images that are photos, jpeg should be preferred, while png is better for /// screenshots and digital arts.</param> /// <param name="size">The size for the thumbnail image.</param> /// <param name="mode">How to resize and crop the image to achieve the desired /// size.</param> /// <returns>The task that represents the asynchronous send operation. The TResult /// parameter contains the response from the server.</returns> /// <exception cref="Dropbox.Api.ApiException{TError}">Thrown if there is an error /// processing the request; This will contain a <see /// cref="ThumbnailV2Error"/>.</exception> public t.Task <enc.IDownloadResponse <PreviewResult> > GetThumbnailV2Async(PathOrLink resource, ThumbnailFormat format = null, ThumbnailSize size = null, ThumbnailMode mode = null) { var thumbnailV2Arg = new ThumbnailV2Arg(resource, format, size, mode); return(this.GetThumbnailV2Async(thumbnailV2Arg)); }
private string ThumbnailFormatString(ThumbnailFormat format) { switch (format) { case ThumbnailFormat.Jpeg: return("jpeg"); case ThumbnailFormat.Png: return("png"); default: return("jpeg"); } }
/// <summary> /// <para>Begins an asynchronous send to the get thumbnail route.</para> /// </summary> /// <param name="resource">Information specifying which file to preview. This could be /// a path to a file, a shared link pointing to a file, or a shared link pointing to a /// folder, with a relative path.</param> /// <param name="format">The format for the thumbnail image, jpeg (default) or png. For /// images that are photos, jpeg should be preferred, while png is better for /// screenshots and digital arts.</param> /// <param name="size">The size for the thumbnail image.</param> /// <param name="mode">How to resize and crop the image to achieve the desired /// size.</param> /// <param name="callback">The method to be called when the asynchronous send is /// completed.</param> /// <param name="callbackState">A user provided object that distinguished this send /// from other send requests.</param> /// <returns>An object that represents the asynchronous send request.</returns> public sys.IAsyncResult BeginGetThumbnailV2(PathOrLink resource, ThumbnailFormat format = null, ThumbnailSize size = null, ThumbnailMode mode = null, sys.AsyncCallback callback = null, object callbackState = null) { var thumbnailV2Arg = new ThumbnailV2Arg(resource, format, size, mode); return(this.BeginGetThumbnailV2(thumbnailV2Arg, callback, callbackState)); }
protected override void SerializeToStream(CitpBinaryWriter writer) { base.SerializeToStream(writer); switch (Version) { case MsexVersion.Version1_0: writer.Write((byte)LibraryType); writer.Write(LibraryNumber); writer.Write(ThumbnailFormat.GetCustomAttribute <CitpId>().Id); writer.Write(ThumbnailWidth); writer.Write(ThumbnailHeight); writer.Write((ushort)ThumbnailBuffer.Length); writer.Write(ThumbnailBuffer); break; case MsexVersion.Version1_1: case MsexVersion.Version1_2: writer.Write((byte)LibraryType); if (!LibraryId.HasValue) { throw new InvalidOperationException("LibraryId has no value. Required for MSEX V1.1 & V1.2"); } writer.Write(LibraryId.Value.ToByteArray()); writer.Write(ThumbnailFormat.GetCustomAttribute <CitpId>().Id); writer.Write(ThumbnailWidth); writer.Write(ThumbnailHeight); writer.Write((ushort)ThumbnailBuffer.Length); writer.Write(ThumbnailBuffer); break; } }
/// <summary> /// <para>Begins an asynchronous send to the get thumbnail route.</para> /// </summary> /// <param name="path">The path to the image file you want to thumbnail.</param> /// <param name="format">The format for the thumbnail image, jpeg (default) or png. For /// images that are photos, jpeg should be preferred, while png is better for /// screenshots and digital arts.</param> /// <param name="size">The size for the thumbnail image.</param> /// <param name="callback">The method to be called when the asynchronous send is /// completed.</param> /// <param name="callbackState">A user provided object that distinguished this send /// from other send requests.</param> /// <returns>An object that represents the asynchronous send request.</returns> public sys.IAsyncResult BeginGetThumbnail(string path, ThumbnailFormat format = null, ThumbnailSize size = null, sys.AsyncCallback callback = null, object callbackState = null) { var thumbnailArg = new ThumbnailArg(path, format, size); return this.BeginGetThumbnail(thumbnailArg, callback, callbackState); }
/// <summary> /// <para>Get a thumbnail for an image.</para> /// <para>This method currently supports files with the following file extensions: jpg, /// jpeg, png, tiff, tif, gif and bmp. Photos that are larger than 20MB in size won't /// be converted to a thumbnail.</para> /// </summary> /// <param name="path">The path to the image file you want to thumbnail.</param> /// <param name="format">The format for the thumbnail image, jpeg (default) or png. For /// images that are photos, jpeg should be preferred, while png is better for /// screenshots and digital arts.</param> /// <param name="size">The size for the thumbnail image.</param> /// <returns>The task that represents the asynchronous send operation. The TResult /// parameter contains the response from the server.</returns> /// <exception cref="Dropbox.Api.ApiException{ThumbnailError}">Thrown if there is an /// error processing the request; This will contain a <see /// cref="ThumbnailError"/>.</exception> public t.Task<enc.IDownloadResponse<FileMetadata>> GetThumbnailAsync(string path, ThumbnailFormat format = null, ThumbnailSize size = null) { var thumbnailArg = new ThumbnailArg(path, format, size); return this.GetThumbnailAsync(thumbnailArg); }
/// <summary> /// Asynchronously downloads a thumbnail for an image and its metadata. /// </summary> /// <param name="path"> /// The Dropbox path to the image file you want to thumbnail, relative to root. /// </param> /// <param name="format">The image format of the thumbnail to download.</param> /// <param name="size">The size of the thumbnail to download.</param> /// <param name="operationCompleted"> /// The <code>Action<></code> to perform when the asynchronous request completes. /// Provides a <see cref="DropboxFile"/> object containing the thumbnail's content and metadata. /// </param> /// <returns> /// A <see cref="RestOperationCanceler"/> instance that allows to cancel the asynchronous operation. /// </returns> /// <exception cref="DropboxApiException">If there is an error while communicating with Dropbox.</exception> public RestOperationCanceler DownloadThumbnailAsync(string path, ThumbnailFormat format, ThumbnailSize size, Action<RestOperationCompletedEventArgs<DropboxFile>> operationCompleted) { return this.RestTemplate.GetForObjectAsync<DropboxFile>(this.BuildThumbnailsUrl(path, format, size), operationCompleted); }
/// <summary> /// Asynchronously downloads a thumbnail for an image and its metadata. /// </summary> /// <param name="path"> /// The Dropbox path to the image file you want to thumbnail, relative to root. /// </param> /// <param name="format">The image format of the thumbnail to download.</param> /// <param name="size">The size of the thumbnail to download.</param> /// <returns> /// A <code>Task</code> that represents the asynchronous operation that can return /// a <see cref="DropboxFile"/> object containing the thumbnail's content and metadata. /// </returns> /// <exception cref="DropboxApiException">If there is an error while communicating with Dropbox.</exception> public Task<DropboxFile> DownloadThumbnailAsync(string path, ThumbnailFormat format, ThumbnailSize size) { return this.RestTemplate.GetForObjectAsync<DropboxFile>(this.BuildThumbnailsUrl(path, format, size)); }
private string BuildThumbnailsUrl(string dropboxPath, ThumbnailFormat format, ThumbnailSize size) { NameValueCollection parameters = new NameValueCollection(); parameters.Add("format", format.ToString().ToUpper()); parameters.Add("size", ThumbnailSizeToString(size)); return this.BuildUrl("https://api-content.dropbox.com/1/thumbnails/", dropboxPath, parameters); }
protected override void SerializeToStream(CitpBinaryWriter writer) { base.SerializeToStream(writer); switch (Version) { case MsexVersion.Version1_0: writer.Write(ThumbnailFormat.GetCustomAttribute <CitpId>().Id); writer.Write(ThumbnailWidth); writer.Write(ThumbnailHeight); writer.Write((byte)ThumbnailFlags); writer.Write((byte)LibraryType); writer.Write(LibraryNumber); if (ShouldRequestAllThumbnails) { writer.Write((byte)0x00); } else { writer.Write((byte)ElementNumbers.Count); foreach (byte e in ElementNumbers) { writer.Write(e); } } break; case MsexVersion.Version1_1: writer.Write(ThumbnailFormat.GetCustomAttribute <CitpId>().Id); writer.Write(ThumbnailWidth); writer.Write(ThumbnailHeight); writer.Write((byte)ThumbnailFlags); writer.Write((byte)LibraryType); if (!LibraryId.HasValue) { throw new InvalidOperationException("LibraryId has no value. Required for MSEX V1.1"); } writer.Write(LibraryId.Value.ToByteArray()); if (ShouldRequestAllThumbnails) { writer.Write((byte)0x00); } else { writer.Write((byte)ElementNumbers.Count); foreach (byte e in ElementNumbers) { writer.Write(e); } } break; case MsexVersion.Version1_2: writer.Write(ThumbnailFormat.GetCustomAttribute <CitpId>().Id); writer.Write(ThumbnailWidth); writer.Write(ThumbnailHeight); writer.Write((byte)ThumbnailFlags); writer.Write((byte)LibraryType); if (!LibraryId.HasValue) { throw new InvalidOperationException("LibraryId has no value. Required for MSEX V1.2"); } writer.Write(LibraryId.Value.ToByteArray()); if (ShouldRequestAllThumbnails) { writer.Write((ushort)0x0000); } else { writer.Write((ushort)ElementNumbers.Count); foreach (byte e in ElementNumbers) { writer.Write(e); } } break; } }
protected override void SerializeToStream(CitpBinaryWriter writer) { base.SerializeToStream(writer); switch (Version) { case MsexVersion.Version1_0: writer.Write(ThumbnailFormat.GetCustomAttribute <CitpId>().Id); writer.Write(ThumbnailWidth); writer.Write(ThumbnailHeight); writer.Write((byte)ThumbnailFlags); writer.Write((byte)LibraryType); if (ShouldRequestAllThumbnails) { writer.Write((byte)0x00); } else { writer.Write((byte)LibraryIds.Count); foreach (var l in LibraryIds) { writer.Write(l.ToByteArray()); } } break; case MsexVersion.Version1_1: writer.Write(ThumbnailFormat.GetCustomAttribute <CitpId>().Id); writer.Write(ThumbnailWidth); writer.Write(ThumbnailHeight); writer.Write((byte)ThumbnailFlags); writer.Write((byte)LibraryType); if (ShouldRequestAllThumbnails) { writer.Write((byte)0x00); } else { writer.Write((byte)LibraryIds.Count); foreach (var l in LibraryIds) { writer.Write(l.ToByteArray()); } } break; case MsexVersion.Version1_2: writer.Write(ThumbnailFormat.GetCustomAttribute <CitpId>().Id); writer.Write(ThumbnailWidth); writer.Write(ThumbnailHeight); writer.Write((byte)ThumbnailFlags); writer.Write((byte)LibraryType); if (ShouldRequestAllThumbnails) { writer.Write((ushort)0x0000); } else { writer.Write((ushort)LibraryIds.Count); foreach (var l in LibraryIds) { writer.Write(l.ToByteArray()); } } break; } }
public async Task <IDownloadResponse <FileMetadata> > GetThumbnailAsync(string path, ThumbnailFormat format = null, ThumbnailSize size = null, ThumbnailMode mode = null) => await _dropBoxClient.Files.GetThumbnailAsync(path, format, size, mode);