public ImageJSON Upload() { try { MultipartFormDataParser parser = new MultipartFormDataParser(HttpContext.Current.Request.InputStream); ImageJSON imageJson = new ImageJSON(); int uploadImageId = 0; // Single file access: FilePart file = parser.Files.First(); string filename = file.FileName; if (file != null && file.Data != null) { // Save the file to db Application.Services.Abstract.DTO.IImage image = new Application.Services.DTO.Image(); image.UserImage = parser.ReadFully(file.Data); uploadImageId = _imageService.UploadImage(image); imageJson.UploadedImageId = uploadImageId; } else { throw new WebException("The posted file was not recognised.", WebExceptionStatus.SendFailure); } return(imageJson); } catch (Exception ex) { _logger.Error(ex); throw ex; } }
public ImageJSON Save(FacebookJSON facebookJson) { int uploadImageId = 0; Application.Services.Abstract.DTO.IImage image; try { WebRequest request = WebRequest.Create(facebookJson.ImageUrl); WebResponse response = request.GetResponse(); using (var stream = response.GetResponseStream()) { if (stream == null) { return(null); } image = new Application.Services.DTO.Image() { UserImage = ImageSericeHelper.Get(stream) }; } //// Save the file to db uploadImageId = _imageService.UploadImage(image); } catch (Exception ex) { _logger.Error(ex); throw; } return(new ImageJSON() { UploadedImageId = uploadImageId }); }