Esempio n. 1
0
        /// <summary>
        /// Generates link for the file with required parameters.
        /// </summary>
        /// <param name="userID">A string containing the user id.</param>
        /// <param name="fileName">A string containing the file name.</param>
        /// <param name="fileClassfication">An enum that is specifying the file classification.</param>
        /// <param name="requiredDimension">An unsigned integer specifying the required dimensions.</param>
        /// <param name="senderID">A string containing sender user id. Required only getting url of offline file.</param>
        /// <remarks>Dimensions should be greater than 0 and less than the actual dimension of the file. If dimension is 0 or greater than the actual dimension of the image, image with actual dimensions will be returned.</remarks>
        /// <returns>A string containing the url for getting the file.</returns>
        public static string BuildFileUrl(string fileServer, string fileName, FileCategory fileClassfication, MediaType mediaType)
        {
            string fileStorePort             = ConfigurationManager.AppSettings[NeeoConstants.FileStorePort];
            string imageHandler              = ConfigurationManager.AppSettings[NeeoConstants.ImageHandler];
            string webProtocol               = ConfigurationManager.AppSettings[NeeoConstants.WebProtocol];
            string idQString                 = "?id=" + fileName;
            string fileClassificationQString = "&fc=" + fileClassfication.ToString("D");
            string mediaTypeQString          = "&mt=" + mediaType.ToString("D");
            string signatureQString          = "&sig=" + NeeoUtility.GenerateSignature(fileName + fileClassfication.ToString("D") + mediaType.ToString("D"));
            string url = webProtocol + "://" + fileServer + (NeeoUtility.IsNullOrEmpty(fileStorePort) == false ? (":" + fileStorePort + "/") : "/") + imageHandler + idQString + fileClassificationQString + mediaTypeQString + signatureQString;

            return(url);
        }
Esempio n. 2
0
        /// <summary>
        /// Processes the http request to send the required response.
        /// </summary>
        /// <remarks>It is used to send image data to the requester if the request  </remarks>
        /// <param name="context">An object holding http context object for setting up response header on sending response.</param>
        public void ProcessRequest(HttpContext context)
        {
            _httpContext = context;
            LibNeeo.IO.File file      = null;
            ulong           timeStamp = 0;
            short           fileClass = 0;

            if (!NeeoUtility.IsNullOrEmpty(context.Request.QueryString["id"]) &&
                !NeeoUtility.IsNullOrEmpty(context.Request.QueryString["sig"]) &&
                !NeeoUtility.IsNullOrEmpty(context.Request.QueryString["fc"]) &&
                !NeeoUtility.IsNullOrEmpty(context.Request.QueryString["mt"]))
            {
                string       fileID       = HttpUtility.UrlEncode(context.Request.QueryString["id"].ToString());
                FileCategory fileCategory = (FileCategory)Convert.ToInt16(context.Request.QueryString["fc"]);
                MediaType    mediaType    = (MediaType)Convert.ToInt16(context.Request.QueryString["mt"]);

                if (NeeoUtility.GenerateSignature(fileID + fileCategory.ToString("D") + mediaType.ToString("D")) == context.Request.QueryString["sig"].ToString())
                {
                    file = GetRequestedFile(fileID, fileCategory, mediaType);
                    if (file != null)
                    {
                        SetResponseWithFileData(file);
                    }
                    else
                    {
                        Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "File ID: " + fileID + ", File Category: Shared, Status: File does not exists.");
                    }
                }
            }
            else if (!NeeoUtility.IsNullOrEmpty(context.Request.QueryString["id"]) &&
                     !NeeoUtility.IsNullOrEmpty(context.Request.QueryString["sig"]))
            {
                // This part is to give backward compatibility for shared file service given with release 3
                string fileID = HttpUtility.UrlEncode(context.Request.QueryString["id"].ToString());

                if (NeeoUtility.GenerateSignature(fileID) == context.Request.QueryString["sig"].ToString())
                {
                    file = GetRequestedFile(fileID, FileCategory.Shared, MediaType.Image);
                    if (file != null)
                    {
                        SetResponseWithFileData(file);
                    }
                    else
                    {
                        Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "File ID: " + fileID + ", File Category: Group, Status: File does not exists.");
                    }
                }
            }
            SetResponseHeaders((int)HttpStatusCode.BadRequest);
        }
Esempio n. 3
0
 public HttpResponseMessage Get([FromUri] FileRequest fileRequest)
 {
     if (!ModelState.IsValid)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Bad Request"));
     }
     if (NeeoUtility.GenerateSignature(fileRequest.Name + fileRequest.FileCategory.ToString("D") + fileRequest.MediaType.ToString("D")) == fileRequest.Signature)
     {
         byte[] fileBytes;
         var    file = GetRequestedFile(fileRequest);
         if (file != null)
         {
             if (Request.Headers.Range != null)
             {
                 var delimeter   = new char[] { '-', '=' };
                 var rangeValues = Request.Headers.Range.ToString().Split(delimeter);
                 if (rangeValues.Length != 3)
                 {
                     return(Request.CreateResponse(HttpStatusCode.BadRequest));
                 }
                 if (!((Convert.ToInt64(rangeValues[1]) <= Convert.ToInt64(rangeValues[2])) && (Convert.ToInt64(rangeValues[2]) <= file.Info.Length)))
                 {
                     return(Request.CreateResponse(HttpStatusCode.BadRequest));
                 }
                 fileBytes = File.GetBytesArray(file.Info.FullPath, Convert.ToInt32(rangeValues[1]),
                                                Convert.ToInt32(rangeValues[2]));
             }
             else
             {
                 fileBytes = File.GetBytesArray(file.Info.FullPath);
             }
             var response = Request.CreateResponse(HttpStatusCode.OK);
             response.Content = new ByteArrayContent(fileBytes);
             //new StreamContent(File.GetStream(file.Info.FullPath));
             //response.Content = new StreamContent(new FileStream(fileInfo.FullPath,FileMode.Open));
             response.Content.Headers.ContentType =
                 new MediaTypeHeaderValue(
                     MimeTypeMapping.GetMimeType(file.Info.Extension).GetDescription());
             return(response);
         }
         Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "File ID: " + fileRequest.FullName + ", File Category: Shared, Status: File does not exists.");
     }
     return(Request.CreateResponse(HttpStatusCode.BadRequest, "Bad Request"));
 }