c# - HttpWebRequest odd behaviour -
update looks though issue related this. have chunk of code deal with:
dynamic facebookresponse = facebookclient.batch(new facebookbatchparameter(httpmethod.get, "me"), new facebookbatchparameter(httpmethod.get, "me", new { fields = "picture.type(large)" }));
errr not sure why happening!
i found odd behaviour httpwebrequest.
// send image blob storage. var url = facebookresponse[1]["picture"]["data"]["url"]; byte[] imagebytes; var request = (httpwebrequest)httpwebrequest.create(url); request.timeout = 5000; request.readwritetimeout = 20000; var response = (httpwebresponse)request.getresponse(); var validationresults = _imageservice.uploadprofilepicture(response, url, newuserid).tolist();
on lastly line throwing error saying 'object' not contain definition 'tolist'
if take out of lines before lastly line step function.
possible threading issue maybe?
edit: _imageservice dependency passed controller ninject.
here's uploadprofilepicture function:
public ienumerable<validationresult> uploadprofilepicture(stream s, string filename, int userid) { if (s == null) throw new argumentnullexception("s"); if (userid <= 0) throw new argumentnullexception("userid"); if (s.length <= 0) { yield homecoming new validationresult("", globalresources.filecontainsnocontent); yield break; } var maxprofilepicturesize = int.parse(configurationmanager.appsettings[configurationmanagerconstants.blobmaxprofilepicturesize]); if (s.length > maxprofilepicturesize) { yield homecoming new validationresult("", string.format(globalresources.profilepicturemustbenogreaterthan, configurationmanager.appsettings[configurationmanagerconstants.blobmaxprofilepicturesizefriendlytext])); yield break; } const string defaultextensiontype = ".jpg"; var container = getcloudblobcontainer(configurationmanager.appsettings[configurationmanagerconstants.blobimagecontainername]); var uniqueblobname = string.format(configurationmanager.appsettings[configurationmanagerconstants.blobuserprofilepicturepath], userid, defaultextensiontype); var blob = container.getblockblobreference(uniqueblobname); blob.properties.contenttype = "image/jpeg"; var uploadimageextension = path.getextension(filename); if (!string.isnullorwhitespace(uploadimageextension) && !uploadimageextension.equals(defaultextensiontype, stringcomparison.invariantcultureignorecase)) { using (var ms = new memorystream()) { imagebuilder.current.build(s, ms, new resizesettings("format=jpg")); ms.seek(0, seekorigin.begin); blob.uploadfromstream(ms); } } else { blob.uploadfromstream(s); } }
c# asp.net-mvc httpwebrequest
No comments:
Post a Comment