GAE上传图片,新增大对象数据的问题

本文介绍了如何使用Google App Engine (GAE) 通过Picasa Web Albums Data API上传图片,并分享了处理大数据字段时遇到的问题及解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前一段时间公司做了一个GAE的Demo,Demo地址在
[url]http://www.easygae.com/Product/view/id/ag5kYXRvbmdzb2Z0d2FyZXINCxIHUHJvZHVjdBgHDA.html[/url]
如果想了解GAE的请到下面的网站查看
[url]http://code.google.com/intl/zh-CN/appengine/docs/whatisgoogleappengine.html[/url]
里面有相关的介绍,就不多说了, 下面就将碰到的问题讲讲吧
GAE上传图片时要调用Google的Picasa Web Albums Data API,请参考下面的网站
[url]http://code.google.com/apis/gdata/[/url]
Google的数据处理的API都在里面有介绍.
下面将上传图片的步骤讲一下:
1.申请一个http://picasaweb.google.com相簿ID(albumid),并获取用户名
2.下载Google Data的JAR,下载地址:
[url]http://code.google.com/p/gdata-java-client/downloads/list[/url]

上传图片时假定已经申请了Google相簿,如果没有请到http://picasaweb.google.com申请相簿,并记录相簿ID.
下面将代码贴出来看一下,我用的是Serlvet上传,上传组件是commons-fileupload-1.2.1.jar
PicasawebService picasawebService = new PicasawebService("easygae");
String username = "";//用户名
String passwd = ""; //密码
String albumid=""; //相簿ID
picasawebService.setUserCredentials(username, passwd);
String oldPhotoid = photoInfo.getPhotoid();
PhotoEntry oldEntry = (PhotoEntry)picasawebService.getEntry(new URL(oldPhotoid), PhotoEntry.class);
//先刪除圖片,然後新增
if(oldEntry!=null)
oldEntry.delete();
//相簿地址
String albumPostUrl = "http://picasaweb.google.com/data/feed/api/user/"+username+"/albumid/"+albumid;
PhotoEntry photoEntry = new PhotoEntry();
photoEntry.setTitle(new PlainTextConstruct(photoInfo.getTitle()));
photoEntry.setDescription(new PlainTextConstruct(
photoInfo.getDescription()));
photoEntry.setClient(applicationName);
photoEntry.setContent(photoInfo.getOtherContent());
// 上传图片
PhotoEntry returnedPhoto = picasawebService.insert(new URL(albumPostUrl),
photoEntry);
MediaContent content = (MediaContent)returnedPhoto.getContent();
photoInfo.setPicURL(content.getUri()) ;
photoInfo.setPhotoid(returnedPhoto.getId());

另外GAE新增大数据时,我Model的栏位类型是String,心想String的最大长度是4G,保存大字段时应该没问题,谁知道超过了500字时就自动截取了,後來用
@Persistent
private com.google.appengine.api.datastore.Text siteContent ;
就可以保存进去了.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值