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
Post a Comment