Storing Images as binary in DB from external URL
I am currently in the midst of migrating a site from ZenCart to NopCommerce (PHP to .Net). I am writing a routine to transfer the products from one to the other. I have finished this now with only one aspect remaining, the images. In Zencart, the location of the image is stored in the database, but in NopCommerce its s开发者_Python百科tored as a binary in the database.
Can anyone help with a way to write images to an SQL Server DB as binary from an external url.
You can easily use the WebClient
class or the HttpWebRequest
/HttpWebResponse
to fetch the images at a particular url.
You would call the DownloadData
method on the WebClient
class or call the GetResponseStream
method on the HttpWebResponse
returned from a call to HttpWebRequest.GetResponse
to get the bytes.
Then, you can insert the blobs into your DB as normal.
精彩评论