0

UPDATE It looks as though the issue is related to this. I have this chunk of code to 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 this is happening!

I found some odd behaviour HttpWebRequest.

// Send the image to 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 the last line its throwing an error saying 'object' does not contain a definition for 'ToList' but if I take out all of the lines before the last line it will step into the function.

Possible threading issue maybe?

EDIT: _imageService is just a dependency passed into the controller with Ninject.

Here's the 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 return new ValidationResult("", GlobalResources.FileContainsNoContent);
        yield break;
    }

    var maxProfilePictureSize = int.Parse(ConfigurationManager.AppSettings[ConfigurationManagerConstants.BlobMaxProfilePictureSize]);
    if (s.Length > maxProfilePictureSize)
    {
        yield return 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);
    }
}
Community
  • 1
  • 1
Ryan
  • 4,354
  • 2
  • 42
  • 78

0 Answers0