UploadPicture() public method

UploadPicture method that does all the uploading work.
public UploadPicture ( Stream stream, string title, string description, string tags, int isPublic, int isFamily, int isFriend ) : string
stream Stream The object containing the pphoto to be uploaded.
title string The title of the photo (optional).
description string The description of the photograph (optional).
tags string The tags for the photograph (optional).
isPublic int 0 for private, 1 for public.
isFamily int 1 if family, 0 is not.
isFriend int 1 if friend, 0 if not.
return string
Exemplo n.º 1
3
        public IPhoto UploadPhoto(Stream stream, string filename, string title, string description, string tags)
        {
            using (MiniProfiler.Current.Step("FlickrPhotoRepository.UploadPhoto"))
            {
                Flickr fl = new Flickr();

                string authToken = (ConfigurationManager.AppSettings["FlickrAuth"] ?? "").ToString();
                if (string.IsNullOrEmpty(authToken))
                    throw new ApplicationException("Missing Flickr Authorization");

                fl.AuthToken = authToken;
                string photoID = fl.UploadPicture(stream, filename, title, description, tags, true, true, false,
                    ContentType.Photo, SafetyLevel.Safe, HiddenFromSearch.Visible);
                var photo = fl.PhotosGetInfo(photoID);
                var allSets = fl.PhotosetsGetList();
                var blogSet = allSets
                                .FirstOrDefault(s => s.Description == "Blog Uploads");
                if (blogSet != null)
                    fl.PhotosetsAddPhoto(blogSet.PhotosetId, photo.PhotoId);

                FlickrPhoto fphoto = new FlickrPhoto();
                fphoto.Description = photo.Description;
                fphoto.WebUrl = photo.MediumUrl;
                fphoto.Title = photo.Title;
                fphoto.Description = photo.Description;

                return fphoto;
            }
        }
        public string Upload(WitnessKingTidesApiInputModel model)
        {
            string flickrId = string.Empty;
            model.FileName = Guid.NewGuid().ToString() + ".jpg";

            var flickr = new Flickr(FlickrApiKey, FlickrApiSecret);
            flickr.OAuthAccessToken = FlickrOAuthKey;
            flickr.OAuthAccessTokenSecret = FlickrOAuthSecret;

            var path = Path.Combine(AppDataDirectory, model.FileName);
            using (var stream = File.OpenWrite(path))
            {
                stream.Write(model.Photo, 0, model.Photo.Length);
            }

            //TODO: We should probably fill the title here. Otherwise default flickr captions will be gibberish guids
            flickrId = flickr.UploadPicture(path, null, model.Description, null, true, false, false);

            //TODO: Should probably try/catch this section here. Failure to set location and/or delete the temp file should
            //not signal a failed upload.

            //TODO: Need to check if coordinates can be embedded in EXIF and extracted by Flickr. If so we can probably
            //skip this and embed the coordinates client-side.
            flickr.PhotosGeoSetLocation(flickrId, Convert.ToDouble(model.Latitude), Convert.ToDouble(model.Longitude));

            File.Delete(path);

            return flickrId;
        }
Exemplo n.º 3
0
        void Consume()
        {
            IFileItem photo;

            do
            {
                lock (locker) {
                    while (taskQ.Count == 0)
                    {
                        Monitor.Wait(locker);
                    }

                    photo = taskQ.Dequeue();
                }

                if (photo != null)
                {
                    try {
                        Services.Application.RunOnMainThread(() => dialog.IncrementProgress(photo.Name));
                        flickr.UploadPicture(photo.Path, photo.Name, "", UploadTags, AccountConfig.IsPublic, AccountConfig.FamilyAllowed,
                                             AccountConfig.FriendsAllowed);
                    } catch (FlickrApiException e) {
                        Log <UploadAction> .Error("Cannot upload photos, please grant permissions in configuration dialog");
                    }
                }
                else
                {
                    Log <UploadPool> .Debug("Thread reached the end of queue");
                }
            } while (photo != null);
        }
Exemplo n.º 4
0
        public string UploadPhotographToFlickr(string flickrAuth, string title, string description, string path, string tag)
        {
            try
            {
                flickr.AuthToken = flickrAuth;

                bool uploadAsPublic = true;

                string photoId = flickr.UploadPicture(ConfigurationManager.AppSettings["TempFileLocalPath"].ToString(), title, description, tag, uploadAsPublic, false, false);
                if (photoId != null && photoId != "")
                {
                    bool setFlag = false;

                    // Get list of users sets
                    PhotosetCollection sets = flickr.PhotosetsGetList();

                    //add photo to appropriate skichair photoset
                    foreach (Photoset set in sets)
                    {
                        if (set.Title.Equals(tag))
                        {
                            setFlag = true;
                            //add the photo to that set
                            AddPhotoToPhotoset(set.PhotosetId, photoId);
                            break;
                        }
                    }

                    //if photoset didn't exist create it
                    if (!setFlag)
                    {
                        //create photoset and add photo to it
                        CreateFlickrPhotoSet(tag, photoId);
                        flickr.GroupsPoolsAdd(photoId, Utility.FlickrGroupID);
                    }

                    return(photoId);
                }
                else
                {
                    return("");
                }
            }
            catch (Exception ex)
            {
                System.IO.StreamWriter sw = System.IO.File.AppendText(ConfigurationManager.AppSettings["ErrorLogPath"].ToString() + "SkiChairErrorLogFile.txt");
                try
                {
                    string logLine = System.String.Format("{0:G}: {1}.", System.DateTime.Now, "Error: " + ex.Message);
                    sw.WriteLine(logLine);
                }
                finally
                {
                    sw.Close();
                }
                return("");
            }
        }
Exemplo n.º 5
0
        private void UploadFileButton_Click(object sender, EventArgs e)
        {
            Flickr flickr = new Flickr(ApiKey.Text, SharedSecret.Text, AuthToken.Text);

            bool uploadAsPublic = false;

            string title = "Test Upload";
            string description = "Test Description";

            string photoId = flickr.UploadPicture(Filename.Text, title, description, "", uploadAsPublic, false, false);

            OutputTextbox.Text = "Photo uploaded Successfully\r\n";
            OutputTextbox.Text += "Photo Id = " + photoId + "\r\n";
        }
Exemplo n.º 6
0
        public static void UploadPicture(string filename, string title, string description, bool uploadAsPublic)
        {
            try
            {
                Flickr flickr = new Flickr(ApiKey, SharedSecret, authToken);

                string photoId = flickr.UploadPicture(ConfigManager.ssStorageDir + "\\" + filename, title, description, "", uploadAsPublic, false, false);

                LastUploadAction = "Photo uploaded successfully ID: " + photoId;
            }
            catch
            {
                LastUploadAction = "Last UploadPicture Failed.";
            }
        }
Exemplo n.º 7
0
        private void persistableOutput_ImageCaptured(object sender, ImageCapturedEventArgs e)
        {
            FileStream stream1 = new FileStream(e.ImageNames.FullSize, FileMode.CreateNew);

            e.FullSizeImage.Save(stream1, ImageFormat.Png);
            stream1.Close();
            if (e.IsThumbnailed)
            {
                stream1 = new FileStream(e.ImageNames.Thumbnail, FileMode.CreateNew);
                e.ThumbnailImage.Save(stream1, ImageFormat.Png);
                stream1.Close();
            }
            if (this.ConfigExists)
            {
                Settings         settings1 = new Settings(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\AltmanSoftware.Cropper.FlickrOutput Plugin\AltmanSoftware.Cropper.FlickrOutput.config");
                FlickrNet.Flickr flickr1   = new FlickrNet.Flickr("ab782e182b4eb406d285211811d625ff", "b080496c05335c3d", settings1.Token);
                PhotoDetails     details1  = new PhotoDetails(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\AltmanSoftware.Cropper.FlickrOutput Plugin\AltmanSoftware.Cropper.FlickrOutput.config");
                if (details1.ShowDialog() == DialogResult.OK)
                {
                    string text1 = flickr1.UploadPicture(e.ImageNames.FullSize, details1.Title, details1.Description, details1.Tags, details1.IsPublic, details1.IsFamily, details1.IsFriend);
                    if ((details1.PhotoSetId != null) && (details1.PhotoSetId != string.Empty))
                    {
                        MessageBox.Show(details1.PhotoSetId);
                        flickr1.PhotosetsAddPhoto(details1.PhotoSetId, text1);
                    }
                    if (e.IsThumbnailed)
                    {
                        string text2 = flickr1.UploadPicture(e.ImageNames.Thumbnail, details1.Title + " Thumbnail", details1.Description, details1.Tags, details1.IsPublic, details1.IsFamily, details1.IsFriend);
                        if ((details1.PhotoSetId != null) && (details1.PhotoSetId != string.Empty))
                        {
                            flickr1.PhotosetsAddPhoto(details1.PhotoSetId, text2);
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
    public Result <UploadPhotoResponse> UploadImage(UploadPhotoRequest request)
    {
        var tags = request.Tags == null ? "" : string.Join(' ', request.Tags);

        var photoId = _flickr.UploadPicture(request.Photo, Guid.NewGuid().ToString(), request.Title, request.Description, tags, request.IsPublic, false, false, ContentType.Photo, SafetyLevel.None, HiddenFromSearch.Hidden);

        var photo = _flickr.PhotosGetInfo(photoId);

        return(Result <UploadPhotoResponse> .Of(new UploadPhotoResponse
        {
            Id = photo.PhotoId,
            Title = photo.Title,
            Latitude = photo.Location?.Latitude,
            Longitude = photo.Location?.Longitude,
            TakenAt = photo.DateTaken,
            ImageUrlLarge = photo.LargeUrl
        }));
    }
        /// <summary>
        /// This will post the picture to flickr with a photo description the FEN Move
        /// </summary>
        /// <param name="assetPath">Flie Location of Image</param>
        /// <param name="GameBoardState">Chess FEN Move to add to Photo Description</param>
        public static Uri postFlickrPic(string assetPath, string GameBoardState)
        {
            try
            {
                string consumerKey = ConfigurationManager.AppSettings["FlickrConsumerKey"];
                string consumerSecret = ConfigurationManager.AppSettings["FlickrConsumerSecret"];
                Flickr flickr = new Flickr(consumerKey, consumerSecret);
                //Step 1 Request a Token
                //OAuthRequestToken OAuthRequestToken = flickr.OAuthGetRequestToken("oob");

                //Step 2 User Authorization
                //string url = flickr.OAuthCalculateAuthorizationUrl(OAuthRequestToken.Token, AuthLevel.Write);
                //This step is needed to get the verifier code only once for the application
                //System.Diagnostics.Process.Start(url);

                //Step 3 Get the Access Token for the application
                //string Verifier = "244-040-435";
                //string requestToken = "72157632741560142-76d6212140a1f3bf";
                //string requestTokenSecret = "53ae3f7e58e24e2e";
                //OAuthAccessToken AccessToken = flickr.OAuthGetAccessToken(requestToken, requestTokenSecret, Verifier);

                //This is the Application Access Token
                flickr.OAuthAccessToken = ConfigurationManager.AppSettings["FlickrOAuthAccessToken"];
                flickr.OAuthAccessTokenSecret = ConfigurationManager.AppSettings["FlickrOAuthAccessTokenSecret"];

                //TODO: Image must be set to public
                string file = assetPath;
                string title = "Chess Game";
                string tags = "chess,chessbybird,superawesome";
                string photoId = flickr.UploadPicture(file, title, GameBoardState, tags, true, true, true);     //TODO: ensure flickr description is JUST the FEN value
                //TODO - fix to use proper Uri
                Uri siteUri = new Uri("http://www.flickr.com/photos/92474796@N06/" + photoId);
                return siteUri;
            }
            catch (Exception)
            {
                throw new System.ArgumentException("Cannot save Flickr image", "flickr");
            }
        }
        public async Task<HttpResponseMessage> PostImage([ValueProvider(typeof(HeaderValueProviderFactory<string>))]
          string sessionKey)
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            // Read the file

            string root = HttpContext.Current.Server.MapPath("~/App_Data");
            var provider = new MultipartFormDataStreamProvider(root);


                if (!Request.Content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }
                using (var db = new BGNewsDB())
                {
                    var user = db.Users.FirstOrDefault(x => x.SessionKey == sessionKey);
                    if (user == null)
                    {
                        return Request.CreateResponse(HttpStatusCode.Unauthorized);
                    }

                    try
                    {
                        // Read the form data.
                        await Request.Content.ReadAsMultipartAsync(provider);

                        // This illustrates how to get the file names.
                        foreach (MultipartFileData file in provider.FileData)
                        {
                            Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                            Trace.WriteLine("Server file path: " + file.LocalFileName);
                            string fileName = file.LocalFileName;
                            Flickr flickr = new Flickr("8429718a57e817718d524ea6366b5b42", "3504e68e5812b923", "72157635282605625-a5feb0f5a53c4467");
                            var result = flickr.UploadPicture(fileName);
                            System.IO.File.Delete(file.LocalFileName);


                            // Take the image urls from flickr

                            Auth auth = flickr.AuthCheckToken("72157635282605625-a5feb0f5a53c4467");
                            PhotoSearchOptions options = new PhotoSearchOptions(auth.User.UserId);
                            options.SortOrder = PhotoSearchSortOrder.DatePostedDescending;
                            options.PerPage = 1;

                            ICollection<Photo> photos = flickr.PhotosSearch(options);

                            Flickr.FlushCache(flickr.LastRequest);

                            Photo photo = photos.First();
                               user.ProfilePictureUrlMedium = photo.MediumUrl;
                               user.ProfilePictureUrlThumbnail = photo.SquareThumbnailUrl;
                            break;

                        }
                       
                     
                        return Request.CreateResponse(HttpStatusCode.Created);
                    }

                    catch (System.Exception e)
                    {
                        return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
                    }
                }
            
        }
Exemplo n.º 11
0
        /// <summary>
        /// Do the actual upload to Flickr
        /// For more details on the available parameters, see: http://flickrnet.codeplex.com
        /// </summary>
        /// <param name="imageData">byte[] with image data</param>
        /// <returns>FlickrResponse</returns>
        public static FlickrInfo UploadToFlickr(byte[] imageData, string title, string filename)
        {
            Flickr flickr = new Flickr(Flickr_API_KEY, Flickr_SHARED_SECRET,config.flickrToken);

            // build the data stream
            Stream data = new MemoryStream(imageData);

            string uploadID = flickr.UploadPicture(data, filename, title, string.Empty, "GreenShot", config.IsPublic, config.IsFamily, config.IsFriend, ContentType.Screenshot, config.SafetyLevel, config.HiddenFromSearch);

            flickr = null;

            return RetrieveFlickrInfo(uploadID);
        }
        public static bool postFlickrPic(string photoDescription)
        {
            string consumerKey = "8d25fce60055946ae5f7e1dff9a5b955";
            string consumerSecret = "0d89b50f8cc4ab5f";

            try
            {
                String assetPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\DigitalAssets\ChessGameboard.PNG");
                Image chessGameboardImage = Image.FromFile(assetPath);

                Flickr flickr = new Flickr(consumerKey, consumerSecret);
                //Step 1 Request a Token
                //OAuthRequestToken OAuthRequestToken = flickr.OAuthGetRequestToken("oob");

                //Step 2 User Authorization
                //string url = flickr.OAuthCalculateAuthorizationUrl(OAuthRequestToken.Token, AuthLevel.Write);
                //This step is needed to get the verifier code only once for the application
                //System.Diagnostics.Process.Start(url);

                //Step 3 Get the Access Token for the application
                //string Verifier = "244-040-435";
                //string requestToken = "72157632741560142-76d6212140a1f3bf";
                //string requestTokenSecret = "53ae3f7e58e24e2e";
                //OAuthAccessToken AccessToken = flickr.OAuthGetAccessToken(requestToken, requestTokenSecret, Verifier);

                //This is the Application Access Token
                flickr.OAuthAccessToken = "72157632734925979-90e9a569b563b919";
                flickr.OAuthAccessTokenSecret = "8b330063711bb116";

                //TODO: Image must be set to public
                string file = assetPath;
                string title = "Test Chess Photo";
                string tags = "tag1,tag2,tag3";
                string photoId = flickr.UploadPicture(file, title, photoDescription, tags);

                return true;
            }
            catch (FileNotFoundException ex)
            {
                //TODO: Email or log ex
                return false;
            }
            catch (WebException ex)
            {
                //TODO: Email or log ex
                return false;
            }
            catch (Exception ex)
            {
                //TODO: Email or log ex
                return false;
            }
        }