Error trying to upload photo

23 views
Skip to first unread message

ScottIsAFool

unread,
Sep 22, 2008, 10:16:55 AM9/22/08
to Google Data APIs .NET Client Library
I'm just playing around with the Picasa Web API, and following some
of
the examples given in the .NET guide (http://code.google.com/apis/
picasaweb/developers_guide_dotnet.html), it lets me view the albums
and create a new album, but when I try and upload a photo, I'm
getting
an exception saying that the URI is incorrect (giving a 400 error).
I'm not doing anything different from the code samples, but this is
just perplexing me.

I should add, this is a winforms app. Anyone else having any issues
with it at the moment?

Frank Mantek

unread,
Sep 22, 2008, 12:47:38 PM9/22/08
to Google GData .NET group, Google Data APIs .NET Client Library
Can you show us how you are uploading? an little Code snippet? The
error could be caused by many things.....

Frank Mantek

Sent from my iPhone

ScottIsAFool

unread,
Sep 23, 2008, 4:46:12 AM9/23/08
to Google Data APIs .NET Client Library
The code I was using is as follows:

PicasaService p_service = new PicasaService("ScottIsAFool-
WLPGPlugin-0.0.0.1");
p_service.setUserCredentials(user, pass);

// Reading Albums

AlbumQuery query = new
AlbumQuery(PicasaQuery.CreatePicasaUri(username));
PicasaFeed feed = p_service.Query(query);
foreach (PicasaEntry entry in feed.Entries)
{
Console.WriteLine(entry.Title.Text);
}

// Adding Albums

AlbumEntry newalbum = new AlbumEntry();
newalbum.Title.Text = "My Test Album2";
newalbum.Summary.Text = "Just for testing purposes";
AlbumAccessor ac = new AlbumAccessor(newalbum);
ac.Access = "public";

Uri feedUri = new
Uri(PhotoQuery.CreatePicasaUri(username));
PicasaEntry createdEntry =
(PicasaEntry)p_service.Insert(feedUri, newalbum);

// Adding a photo
string file = @"d:\pictures\wallpaperl.jpg";
string albumname = "My Test Album";
Uri postUri = new Uri(PhotoQuery.CreatePicasaUri(username,
"default"));

System.IO.FileInfo fileInfo = new
System.IO.FileInfo(file);
System.IO.FileStream fileStream = fileInfo.OpenRead();

PicasaEntry newpic =
(PicasaEntry)p_service.Insert(postUri, fileStream, "image/jpeg",
file);

fileStream.Close();
Console.WriteLine("Done, I hope");

Console.Read();

I've tried it with "default" as well as createdEntry.Title.Text for
the folder name when creating the URI. All of these give the same
error.

On Sep 22, 5:47 pm, Frank Mantek <fman...@gmail.com> wrote:
> Can you show us how you are uploading? an little Code snippet? The  
> error could be caused by many things.....
>
> Frank Mantek
>
> Sent from my iPhone
>

ScottIsAFool

unread,
Sep 23, 2008, 4:50:44 AM9/23/08
to Google Data APIs .NET Client Library
I should note that the variables used (user, pass, username), user was
my email address, and username was the same but without the @gmail.com
(i know i could have just used username instead of user.

Frank Mantek

unread,
Sep 23, 2008, 5:25:13 AM9/23/08
to gdata-dotnet-...@googlegroups.com
If you try to post to the default album, you should use this: 


as the generic post API. The method "createpicasauri" is creating more specialized uri, it creates the "username/albumname/<name>" uri, that is not the post uri.

I should probably have a helper to return above as well.

Frank

ScottIsAFool

unread,
Sep 23, 2008, 11:27:34 AM9/23/08
to Google Data APIs .NET Client Library
I actually tried default as a last resort. When I had been trying it
before, I was using my username (scottisafool) and the name of the
album I had just created, which in the example code above gave me
http://picasaweb.google.com/data/feed/api/user/scottisafool/album/My
Test Album2. Looking at that now, you gave it as albumname, not album.
But the whole URL is coming from the CreatePicasaUri() method. So
which is correct?

Frank Mantek

unread,
Sep 24, 2008, 8:32:04 AM9/24/08
to gdata-dotnet-...@googlegroups.com
The create methods are, in general, helpers to create "Query" uris (as
picasa offers so many different feeds). For posts, i should probably
add another helper = i would recomment doing the following:

a) if you have a feed, use the postUri of the feed
b) if you don't have one, use the URI below, especially if that fixes
your issue. Does it do that?

Frank

ScottIsAFool

unread,
Sep 24, 2008, 8:51:44 AM9/24/08
to Google Data APIs .NET Client Library
Ok, using everything as a default worked. but I want to actually post
to an album I created. I just tried doing it using the
createdEntry.SelfUri.Content property, which gives me the URL of
http://picasaweb.google.com/data/entry/api/user/scottisafool/albumid/5249568249117676417
which then again fails.

Another helper would probably be very useful for post requests :) So
what URI should I be using for this? Cos looking at the documentation,
theres nothing wrong with the URI above...

Juliano Pável Brasil Custódio

unread,
Sep 24, 2008, 9:51:54 AM9/24/08
to Google Data APIs .NET Client Library
I have a FileUpload Control in an asp.net page, which gets the file
chosen by the user and send it do the server. At the server some code like
below make the upload of the file to the album (albumName). This code bellow
works fine for me:

PhotoQuery photos = new PhotoQuery();
PicasaFeed picasaFeed = null;

photos.Uri = new
Uri(PicasaQuery.CreatePicasaUri(service.Credentials.Username.ToString(),
albumName)); //service is a PicasaService object, with credentials set
picasaFeed = (PicasaFeed)service.Query(photos);

Byte[] bFile = fileUpload.FileBytes; //get the file bytes from the
FileUpload Control
Uri postUri = new Uri(picasaFeed.Post);
PicasaEntry entry = service.Insert(postUri, new MemoryStream(bFile),
"image/jpeg", fileUpload.FileName) as PicasaEntry; // save the file at
picasa


Try it.

Juliano


--------------------------------------------------
From: "ScottIsAFool" <scotti...@gmail.com>
Sent: Wednesday, September 24, 2008 9:51 AM
To: "Google Data APIs .NET Client Library"
<gdata-dotnet-...@googlegroups.com>
Subject: [gdata-dotnet-lib] Re: Error trying to upload photo

Reply all
Reply to author
Forward
0 new messages