object IAppController.UploadPhoto(string sessionId, PhotoRqst photo, HttpContext http) { var request = http.Request; var files = request.Files; var count = files.Count; if (count == 0) { throw new ApplicationException("No files in upload request"); } if (count > 1) { throw new ApplicationException($"More than one ({count}) files in upload request"); } var file = files.Get(0); var info = new FileInfo { fileName = file.FileName, contentType = file.ContentType, contentLength = file.ContentLength }; var app = getApp(sessionId); using (var fileStream = file.InputStream) { var response = d.tail(info, () => app.UploadPhoto(photo, fileStream)); return(response); } }
UpPhoto IFacebookApp.UploadPhoto(PhotoRqst photo, Stream fileStream) { var uploadId = photo.uploadId; var token = requirePageToken(photo.pageId); var fbPhoto = _api.UploadPhoto(photo, token, fileStream); _uploader.PhotoIsReady(uploadId, fbPhoto); var reply = new UpPhoto { uploadId = uploadId, photoId = fbPhoto.Id, pageId = photo.pageId, length = photo.fileSize, fileName = photo.fileName, contentType = photo.fileType }; return(reply); }
FbPhoto IGraphApi.UploadPhoto(PhotoRqst photo, string token, Stream fileStream) { var fb = _config.ApiBaseUrl; var pageId = photo.pageId; var url = $"{fb}/{pageId}/photos?published=false&access_token={token}"; using (var mcontent = new MultipartFormDataContent("---------------------------" + DateTime.Now.Ticks.ToString("x"))) { var fcontent = new StreamContent(fileStream); fcontent.Headers.ContentType = new MediaTypeHeaderValue(photo.fileType); mcontent.Add(fcontent, "source", photo.fileName); var info = _web.Post(url, onFbError, mcontent, new { id = "" }); return(new FbPhoto { Id = info.id }); } }
UpPhoto IFacebookApp.UploadPhoto(PhotoRqst photo, Stream fileStream) => d.tail(photo, () => _.UploadPhoto(photo, fileStream));