It looks like - in both examples - you're calling a version of insert that 
performs a multipart request 
https://github.com/google/gdata-java-client/blob/master/java/src/com/google/gdata/client/media/MediaService.java#L372

It also looks like there's a version of insert that performs a 
non-multipart request: 
https://github.com/google/gdata-java-client/blob/master/java/src/com/google/gdata/client/media/MediaService.java#L440
 
so you can probably do something l

 public void insertPhoto()
      throws MalformedURLException, IOException, ServiceException {
    // put path to photo here
    MediaFileSource myMedia = new MediaFileSource(
        new File("some_file.jpg"), "image/jpeg");
    refreshCredential(credential, picasawebService);
    PhotoEntry returnedPhoto = picasawebService.insert(getPhotoFeedUrl(), 
PhotoEntry.class, myMedia);
  }

Note that you can't set the description, and the title will be the filename 
("some_file.jpg"), but that makes the same type of request I've had success 
with.

On Monday, January 30, 2017 at 10:17:48 AM UTC-8, Christian wrote:
>
> Jordan,
> My service code is inserting an image from a URL, and the code looks like 
> this:
> public String addPhotoFromUrl(String urlString, String name)
>       throws IOException, ServiceException {
>     name += "." + FilenameUtils.getExtension(urlString);
>     URL url = new URL(urlString);
>     URLConnection connection = url.openConnection();
>     String contentType = connection.getContentType();
>     PhotoEntry myPhoto = new PhotoEntry();
>     myPhoto.setTitle(new PlainTextConstruct(name));
>     myPhoto.setDescription(new PlainTextConstruct(name));
>     myPhoto.setClient("myClientName");
>     MediaStreamSource mediaStreamSource = new MediaStreamSource(
>         connection.getInputStream(), contentType);
>     mediaStreamSource.setName(name);
>     myPhoto.setMediaSource(mediaStreamSource);
>     refreshCredential(credential, picasawebService);
>     PhotoEntry returnedPhoto = picasawebService.insert(getPhotoFeedUrl(),
>         myPhoto);
>     if (returnedPhoto.getMediaContents().size() > 0) {
>       return returnedPhoto.getMediaContents().get(0).getUrl();
>     }
>     return null;
>   }
>
> Once this quit working, I added a method to this class to play with that 
> loads an image from the file system.  This method looks like this (most of 
> the code is taken directly from the Java Picasa User's guide:
> public void insertPhoto()
>       throws MalformedURLException, IOException, ServiceException {
>     PhotoEntry myPhoto = new PhotoEntry();
>     myPhoto.setTitle(new PlainTextConstruct("Puppies FTW"));
>     myPhoto.setDescription(new PlainTextConstruct("Puppies are the 
> greatest."));
>     myPhoto.setClient("myClientName");
>     // put path to photo here
>     MediaFileSource myMedia = new MediaFileSource(
>         new File("some_file.jpg"), "image/jpeg");
>     myPhoto.setMediaSource(myMedia);
>     refreshCredential(credential, picasawebService);
>     PhotoEntry returnedPhoto = picasawebService.insert(getPhotoFeedUrl(),
>         myPhoto);
>   }
>
> The credential and the picasawebService variables you see in the methods 
> are class member variables, and instantiated via Java Config in Spring.  
> They are fine (as this worked through Friday morning), and I can still 
> successfully progromatically create albums through the code using the 
> credential and picasawebService.
>
> I've run this many times, and get 1 out of every 50-60 tries to upload.  
> Otherwise it gives me the error:
> <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
> <H1>Bad Request</H1>
> <H2>Error 400</H2>
> </BODY>
> </HTML>
>
>     at 
> com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:602)
>     at 
> com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
>     at 
> com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
>     at 
> com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
>     at 
> com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
>     at 
> com.google.gdata.client.media.MediaService.insert(MediaService.java:399)
>
> Any help greatly appreciated, and thank you.
> -Christian
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Picasa Web Albums API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-picasa-data-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to