Represents a upload token.
Inheritance: HyvesEntity
Esempio n. 1
0
        public string GetUploadMediaStatus(UploadToken token)
        {
            string url = string.Format("http://{0}/status?token={1}", token.Ip, HttpUtility.UrlEncode(token.Token));

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);

            webRequest.Method = "GET";

            HttpWebResponse webResponse = null;

            try
            {
                webResponse = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (WebException we)
            {
                webResponse = (HttpWebResponse)we.Response;
            }

            HyvesResponse response = new HyvesResponse(webResponse.GetResponseStream(), HyvesMethod.Unknown);

            if (response.Status == HyvesResponseStatus.Succeeded)
            {
                return(response.RawResponse);
            }

            return(string.Empty);
        }
Esempio n. 2
0
        // TODO: A lot of Refactoring...
        public void UploadMedia(UploadToken token, string fileName, byte[] fileData, string title, string description)
        {
            string NEWLINE  = "\r\n";
            string PREFIX   = "--";
            string boundary = DateTime.Now.Ticks.ToString("x", CultureInfo.InvariantCulture);
            string url      = string.Format("http://{0}/upload?token={1}", token.Ip, HttpUtility.UrlEncode(token.Token));

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);

            webRequest.Method = "POST";
            StringBuilder sb = new StringBuilder();

            sb.Append(PREFIX).Append(boundary).Append(NEWLINE);
            sb.Append("Content-Disposition: form-data; name=\"title\"");
            sb.Append(NEWLINE);
            sb.Append(NEWLINE);
            sb.Append(HttpUtility.UrlEncode(title));
            sb.Append(NEWLINE);

            sb.Append(PREFIX).Append(boundary).Append(NEWLINE);
            sb.Append("Content-Disposition: form-data; name=\"description\"");
            sb.Append(NEWLINE);
            sb.Append(NEWLINE);
            sb.Append(HttpUtility.UrlEncode(description));
            sb.Append(NEWLINE);

            sb.Append(PREFIX).Append(boundary).Append(NEWLINE);
            sb.Append("Content-Disposition: form-data; name=\"file\";");
            sb.Append(" filename=\"");
            sb.Append(fileName);
            sb.Append("\"").Append(NEWLINE);
            sb.Append("Content-Type: image/pjpeg");
            sb.Append(NEWLINE);
            sb.Append(NEWLINE);

            byte[] parameterBytes = Encoding.UTF8.GetBytes(sb.ToString());

            byte[] boundaryBytes = Encoding.UTF8.GetBytes(String.Concat(NEWLINE, PREFIX, boundary, PREFIX, NEWLINE));

            webRequest.ContentType   = string.Format("multipart/form-data; boundary={0}", boundary);
            webRequest.ContentLength = parameterBytes.Length + fileData.Length + +boundaryBytes.Length;

            using (Stream requestStream = webRequest.GetRequestStream())
            {
                requestStream.Write(parameterBytes, 0, parameterBytes.Length);
                requestStream.Write(fileData, 0, fileData.Length);
                requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
            }

            HttpWebResponse webResponse = null;

            try
            {
                webResponse = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (WebException we)
            {
                webResponse = (HttpWebResponse)we.Response;
            }
        }
    public string GetUploadMediaStatus(UploadToken token)
    {
      string url = string.Format("http://{0}/status?token={1}", token.Ip, HttpUtility.UrlEncode(token.Token));

      HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
      webRequest.Method = "GET";
      
      HttpWebResponse webResponse = null;
      try
      {
        webResponse = (HttpWebResponse)webRequest.GetResponse();
      }
      catch (WebException we)
      {
        webResponse = (HttpWebResponse)we.Response;
      }

      HyvesResponse response = new HyvesResponse(webResponse.GetResponseStream(), HyvesMethod.Unknown);
      if (response.Status == HyvesResponseStatus.Succeeded)
      {
        return response.RawResponse;
      }

      return string.Empty;
    }
    // TODO: A lot of Refactoring...
    public void UploadMedia(UploadToken token, string fileName, byte[] fileData, string title, string description)
    {
      string NEWLINE = "\r\n";
      string PREFIX = "--";
      string boundary = DateTime.Now.Ticks.ToString("x", CultureInfo.InvariantCulture);
      string url = string.Format("http://{0}/upload?token={1}", token.Ip, HttpUtility.UrlEncode(token.Token));

      HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
      webRequest.Method = "POST";
      StringBuilder sb = new StringBuilder();

      sb.Append(PREFIX).Append(boundary).Append(NEWLINE);
      sb.Append("Content-Disposition: form-data; name=\"title\"");
      sb.Append(NEWLINE);
      sb.Append(NEWLINE);
      sb.Append(HttpUtility.UrlEncode(title));
      sb.Append(NEWLINE);

      sb.Append(PREFIX).Append(boundary).Append(NEWLINE);
      sb.Append("Content-Disposition: form-data; name=\"description\"");
      sb.Append(NEWLINE);
      sb.Append(NEWLINE);
      sb.Append(HttpUtility.UrlEncode(description));
      sb.Append(NEWLINE);

      sb.Append(PREFIX).Append(boundary).Append(NEWLINE);
      sb.Append("Content-Disposition: form-data; name=\"file\";");
      sb.Append(" filename=\"");
      sb.Append(fileName);
      sb.Append("\"").Append(NEWLINE);
      sb.Append("Content-Type: image/pjpeg");
      sb.Append(NEWLINE);
      sb.Append(NEWLINE);

      byte[] parameterBytes = Encoding.UTF8.GetBytes(sb.ToString());

      byte[] boundaryBytes = Encoding.UTF8.GetBytes(String.Concat(NEWLINE, PREFIX, boundary, PREFIX, NEWLINE));

      webRequest.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
      webRequest.ContentLength = parameterBytes.Length + fileData.Length + + boundaryBytes.Length;

      using (Stream requestStream = webRequest.GetRequestStream())
      {
        requestStream.Write(parameterBytes, 0, parameterBytes.Length);
        requestStream.Write(fileData, 0, fileData.Length);
        requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
      }
      
      HttpWebResponse webResponse = null;
      try
      {
        webResponse = (HttpWebResponse)webRequest.GetResponse();
      }
      catch (WebException we)
      {
        webResponse = (HttpWebResponse)we.Response;
      }      
    }