本文整理汇总了C#中FlickrNet.Flickr.UploadPicture方法的典型用法代码示例。如果您正苦于以下问题:C# Flickr.UploadPicture方法的具体用法?C# Flickr.UploadPicture怎么用?C# Flickr.UploadPicture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FlickrNet.Flickr
的用法示例。
在下文中一共展示了Flickr.UploadPicture方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Upload
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;
}
示例2: UploadPhoto
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;
}
}
示例3: UploadFileButton_Click
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";
}
示例4: UploadPicture
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.";
}
}
示例5: postFlickrPic
/// <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/[email protected]/" + photoId);
return siteUri;
}
catch (Exception)
{
throw new System.ArgumentException("Cannot save Flickr image", "flickr");
}
}
示例6: PostImage
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);
}
}
}
示例7: UploadToFlickr
/// <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);
}
示例8: postFlickrPic
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;
}
}