473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

error when uploading image to fastpic.ru by C#

Hi
I want to upload image to fastpic.ru
this is my code:
Expand|Select|Wrap|Line Numbers
  1. public string UploadImageToFastPic(string uploadfile, string url,string fileFormName, string contenttype)
  2.         {
  3.             if ((fileFormName == null) || (fileFormName.Length == 0))
  4.             {
  5.                 fileFormName = "file";
  6.             }
  7.  
  8.             if ((contenttype == null) || (contenttype.Length == 0))
  9.             {
  10.                 contenttype = "application/octet-stream";
  11.             }
  12.  
  13.             string boundary = "------WebKitFormBoundary" + DateTime.Now.Ticks.ToString("x");
  14.  
  15.             HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
  16.             webrequest.CookieContainer = new CookieContainer();
  17.             webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
  18.             webrequest.Method = "POST";
  19.  
  20.  
  21.             // Build up the post message header
  22.             StringBuilder sb = new StringBuilder();
  23.             sb.Append(boundary);
  24.             sb.Append("\r\n");
  25.             sb.Append("Content-Dis-data; name=\"");
  26.             sb.Append(fileFormName);
  27.             sb.Append("\"; filename=\"");
  28.             sb.Append(Path.GetFileName(uploadfile));
  29.             sb.Append("\"");
  30.             sb.Append("\r\n");
  31.             sb.Append("Content-Type: ");
  32.             sb.Append(contenttype);
  33.             sb.Append("\r\n");
  34.             sb.Append("\r\n");
  35.  
  36.             sb.Append(boundary);
  37.             sb.Append("\r\n");
  38.             sb.Append("Content-Dis-data; name=\"check_thumb\"");
  39.             sb.Append("\r\n");
  40.             sb.Append("\r\n");
  41.  
  42.             sb.Append("size");
  43.             sb.Append("\r\n");
  44.             sb.Append(boundary);
  45.             sb.Append("\r\n");
  46.             sb.Append("Content-Dis-data; name=\"thumb_text\"");
  47.             sb.Append("\r\n");
  48.             sb.Append("\r\n");
  49.  
  50.             sb.Append("Увеличить");
  51.             sb.Append("\r\n");
  52.             sb.Append(boundary);
  53.             sb.Append("\r\n");
  54.             sb.Append("Content-Dis-data; name=\"thumb_size\"");
  55.             sb.Append("\r\n");
  56.             sb.Append("\r\n");
  57.  
  58.             sb.Append("170");
  59.             sb.Append("\r\n");
  60.             sb.Append(boundary);
  61.             sb.Append("\r\n");
  62.             sb.Append("Content-Dis-data; name=\"res_select\"");
  63.             sb.Append("\r\n");
  64.             sb.Append("\r\n");
  65.  
  66.             sb.Append("500");
  67.             sb.Append("\r\n");
  68.             sb.Append(boundary);
  69.             sb.Append("\r\n");
  70.             sb.Append("Content-Dis-data; name=\"orig_resize\"");
  71.             sb.Append("\r\n");
  72.             sb.Append("\r\n");
  73.  
  74.             sb.Append("500");
  75.             sb.Append("\r\n");
  76.             sb.Append(boundary);
  77.             sb.Append("\r\n");
  78.             sb.Append("Content-Dis-data; name=\"orig_rotate\"");
  79.             sb.Append("\r\n");
  80.             sb.Append("\r\n");
  81.  
  82.             sb.Append("0");
  83.             sb.Append("\r\n");
  84.             sb.Append(boundary);
  85.             sb.Append("\r\n");
  86.             sb.Append("Content-Dis-data; name=\"jpeg_quality\"");
  87.             sb.Append("\r\n");
  88.             sb.Append("\r\n");
  89.  
  90.             sb.Append("75");
  91.             sb.Append(boundary);
  92.             sb.Append("Content-Dis-data; name=\"submit\"");
  93.             sb.Append("\r\n");
  94.             sb.Append("\r\n");
  95.  
  96.             sb.Append("Загрузить");
  97.             sb.Append("\r\n");
  98.             sb.Append(boundary);
  99.             sb.Append("\r\n");
  100.             sb.Append("Content-Dis-data; name=\"uploading\"");
  101.             sb.Append("\r\n");
  102.             sb.Append("\r\n");
  103.  
  104.             sb.Append("1");
  105.             sb.Append("\r\n");
  106.             sb.Append(boundary);
  107.             sb.Append("--");
  108.  
  109.             string postHeader = sb.ToString();
  110.             byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);
  111.  
  112.             // Build the trailing boundary string as a byte array
  113.             // ensuring the boundary appears on a line by itself
  114.             byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
  115.  
  116.             FileStream fileStream = new FileStream(uploadfile, FileMode.Open, FileAccess.Read);
  117.             long length = postHeaderBytes.Length + fileStream.Length + boundaryBytes.Length;
  118.             webrequest.ContentLength = length;
  119.  
  120.             Stream requestStream = webrequest.GetRequestStream();
  121.  
  122.             // Write out our post header
  123.             requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
  124.  
  125.             // Write out the file contents
  126.             byte[] buffer = new Byte[checked((uint)Math.Min(4096, (int)fileStream.Length))];
  127.             int bytesRead = 0;
  128.             while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
  129.                 requestStream.Write(buffer, 0, bytesRead);
  130.  
  131.             // Write out the trailing boundary
  132.             requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
  133.             WebResponse responce = webrequest.GetResponse();
  134.             Stream s = responce.GetResponseStream();
  135.             StreamReader sr = new StreamReader(s);
  136.  
  137.             return sr.ReadToEnd();
  138.  
this is my code at from main:
Expand|Select|Wrap|Line Numbers
  1. richTextBox_FullStory.Text = pro.UploadImageToFastPic("E:\\The Haves.jpg","fastpic.ru/uploadmulti", "file[]", "image/jpeg");
I want return result when done function UploadImageToFastpic is content of file .html uploaded file image succussfully

but when function UploadImageToFastpic finished so result return still content of file .html when not uploaded image to fastpic.ru yet

I debug and I realize can't get cookies

SOMEBODY HELP ME, PLEASE !!!!

P/s: the first enter click to fastpic.ru that it appear popup.I don't know thing influence to my code

thank you so much for your help !!!!!!!!!!!
Jun 3 '13 #1
0 1510

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
4
by: joe | last post by:
how to resize an upload image and then change to binary & insert to db
4
by: meseenu | last post by:
Hi every one, iam developing an application where i want to upload image and video files in to a oracle data base. I have used BLOB data type to store the image and video files. iam using...
0
by: aris1234 | last post by:
hello.. How to upload image file in page update ..?? i have logic like this : if user upload new image then old image must delete and update DB used new name if user not upload new image then...
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
5
by: rahia307 | last post by:
hi i want to upload image with epoch date Concatenate. image is load successfully. but when i does not want to image upload then epoch date is store in database i use this code if...
5
by: rahia307 | last post by:
Hi I am using this code for upload image. <table> <form action="process.php method="POST" enctype="multipart/form-data"> <tr> <td align="right">Image1 :</td> <td><input type="file"...
1
n8kindt
by: n8kindt | last post by:
i just spent nearly 3hrs trying to debug this problem so i figured i would post this just in case someone else has the same problem in the future. if you're trying to output binary data as an image...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
2
by: sidhx | last post by:
how can i let image overwriting when uploading? and if uploading an image say "logo.jpg" and if a file already existing say "logo.png" then, how can i replace the file logo.png to logo.jpg(which has...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.