Download images and upload them to the image server

Source: Internet
Author: User

 

[Html]
# Region download the image and upload it to the image server
Public string SaveUrlPics (string strHTML, string path)
{
String picserver = new CommonBLL (). GetItemValue ("PICSERVER"); // obtain the image server address
String [] imgurlAry = GetImgTag (strHTML); // obtain the image address in the document.
Try
{
WebClient wc = new WebClient ();
For (int I = 0; I {
// Temporarily handle this problem. Do not add it multiple times. Do not process the local machine.
If (imgurlAry [I]. IndexOf (picserver) <0)
{
String preStr = DateTime. Now. ToString ("yyyyMMddHHmmssfff ");
PreStr = preStr + imgurlAry [I]. Substring (imgurlAry [I]. LastIndexOf ("."); // obtain image attributes to generate image names
// The downloaded image is stored in the TEMP folder.
Wc. DownloadFile (imgurlAry [I], HttpContext. Current. Server. MapPath (path) + "/" + preStr );
// Upload the image to the image server
PreStr = picserver + "/" + upImg (preStr, dropArtType. SelectedValue );
StrHTML = strHTML. Replace (imgurlAry [I], preStr );
}
}
}
Catch (Exception ex)
{
ShowMessage (ex. Message );
}
Return strHTML;
}
 
# Endregion

# Region download the image and upload it to the image server
Public string SaveUrlPics (string strHTML, string path)
{
String picserver = new CommonBLL (). GetItemValue ("PICSERVER"); // obtain the image server address
String [] imgurlAry = GetImgTag (strHTML); // obtain the image address in the document.
Try
{
WebClient wc = new WebClient ();
For (int I = 0; I {
// Temporarily handle this problem. Do not add it multiple times. Do not process the local machine.
If (imgurlAry [I]. IndexOf (picserver) <0)
{
String preStr = DateTime. Now. ToString ("yyyyMMddHHmmssfff ");
PreStr = preStr + imgurlAry [I]. Substring (imgurlAry [I]. LastIndexOf ("."); // obtain image attributes to generate image names
// The downloaded image is stored in the TEMP folder.
Wc. DownloadFile (imgurlAry [I], HttpContext. Current. Server. MapPath (path) + "/" + preStr );
// Upload the image to the image server
PreStr = picserver + "/" + upImg (preStr, dropArtType. SelectedValue );
StrHTML = strHTML. Replace (imgurlAry [I], preStr );
}
}
}
Catch (Exception ex)
{
ShowMessage (ex. Message );
}
Return strHTML;
}

# Endregion

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.