asp.net - Upload Image from URI to Azure BLOB -


i'd upload images uri postet asp.net mvc5 controller azure blob storage. got working httppostedfilebase, this. can somehow memory stream image uri?

httppostedfilebase hpf = request.files[file] httppostedfilebase; var imgfile = system.drawing.image.fromstream(hpf.inputstream, true, true); cloudblockblob blob = coverscontainer.getblockblobreference("img.jpg"); memorystream stream = new memorystream(); imgfile.save(stream, imageformat.jpeg); stream.position = 0; blob.uploadfromstream(stream); 

so how managed done:

public static image downloadremoteimage(string url) {     httpwebrequest request = (httpwebrequest)webrequest.create(url);     httpwebresponse response;     try     {         response = (httpwebresponse)request.getresponse();     }     catch (exception)     {         return null;     }      // check remote file found. contenttype     // check performed since request non-existent     // image file might redirected 404-page,     // yield statuscode "ok", though image not     // found.     if ((response.statuscode == httpstatuscode.ok ||         response.statuscode == httpstatuscode.moved ||         response.statuscode == httpstatuscode.redirect) &&         response.contenttype.startswith("image", stringcomparison.ordinalignorecase))     {         // if remote file found, download         stream inputstream = response.getresponsestream();         image img = image.fromstream(inputstream);         return img;     }     else     {         return null;     } } 

this code snipped taken , modified question's answer: download image site in .net/c#


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -