Exemple #1
0
        private IActionResult ReturnThumbnailResult(string f, bool json, ThumbnailSize size)
        {
            Response.Headers.Add("x-image-size", new StringValues(size.ToString()));
            var stream      = _thumbnailStorage.ReadStream(ThumbnailNameHelper.Combine(f, size), 50);
            var imageFormat = ExtensionRolesHelper.GetImageFormat(stream);

            if (imageFormat == ExtensionRolesHelper.ImageFormat.unknown)
            {
                SetExpiresResponseHeadersToZero();
                return(NoContent());                // 204
            }

            // When using the api to check using javascript
            // use the cached version of imageFormat, otherwise you have to check if it deleted
            if (json)
            {
                return(Json("OK"));
            }

            stream = _thumbnailStorage.ReadStream(
                ThumbnailNameHelper.Combine(f, size));

            // thumbs are always in jpeg
            Response.Headers.Add("x-filename", new StringValues(FilenamesHelper.GetFileName(f + ".jpg")));
            return(File(stream, "image/jpeg"));
        }
Exemple #2
0
        /// <summary>
        /// Converts this object to json string
        /// </summary>
        /// <returns></returns>
        public string ToJson()
        {
            JObject j = new JObject();

            j["OutputDir"]     = OutPutDir;
            j["SourceName"]    = SourceName;
            j["ThumbnailSize"] = ThumbnailSize.ToString();
            j["LogName"]       = LogName;
            j["Handler"]       = Handlers;
            j["Students"]      = Students;
            return(j.ToString());
        }
Exemple #3
0
        /// <summary>
        /// This method returns a thumbnail by size of a specific file by ID
        /// </summary>
        /// <param name="driveId">The ID of the target drive</param>
        /// <param name="fileId">The ID of the target file</param>
        /// <param name="size">The size of the target thumbnail</param>
        /// <returns>The file thumbnails for the specific file</returns>
        public static Thumbnail GetFileThumbnail(String driveId, String fileId, ThumbnailSize size)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}drives/{1}/items/{2}/thumbnails/0/{3}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveId,
                              fileId,
                              size.ToString().ToLower()));

            var thumbnail = JsonConvert.DeserializeObject <Thumbnail>(jsonResponse);

            return(thumbnail);
        }
Exemple #4
0
        /// <summary>
        /// This method returns the thumbnails of a specific file by ID
        /// </summary>
        /// <param name="driveId">The ID of the target drive</param>
        /// <param name="fileId">The ID of the target file</param>
        /// <returns>The file thumbnails for the specific file</returns>
        public static Stream GetFileThumbnailImage(String driveId, String fileId, ThumbnailSize size)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}drives/{1}/items/{2}/thumbnails/0/{3}",
                    MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                    driveId,
                    fileId,
                    size.ToString().ToLower()));

            var thumbnail = JsonConvert.DeserializeObject<Thumbnail>(jsonResponse);

            var thumbnailImageStream = MicrosoftGraphHelper.MakeGetRequestForStream(
                thumbnail.Url,
                "image/jpeg");

            return (thumbnailImageStream);
        }
        public string UrlFor(string url, ThumbnailSize size)
        {
            Check.Argument.IsNotNullOrEmpty(url, "shortUrl");

            return("{0}?devkey={1}&url={2}&size={3}&root=no".FormatWith(settings.Thumbnail.Endpoint, settings.Thumbnail.ApiKey, url, size.ToString().ToLower(Culture.Invariant)));
        }