Picasa 果然上不了了啊
Sunday, Aug 02 13:15, 2009
0 comments/575 hits
由于公司的网络是墙外的,所以,一直都不知道picasa上不了。上次有人说被GFWed了。还不以为是,结果真的这样了。
啊哈哈,这个世界,真的太搞笑了。
啊哈哈,这个世界,真的太搞笑了。

@authorized.role("admin")
def post(self):
filename = self.request.get('imgfile')
filetitle = self.request.get('imgtitle')
file_handle = StringIO.StringIO(filename) #convert string to file-like object
gd_client = gdata.photos.service.PhotosService()
gd_client.email = 'gzguoer@gmail.com'
gd_client.password = bbpsw.getpassword()
gd_client.source = 'blowblood-upload-image'
gd_client.ProgrammaticLogin()
album_url = '/data/feed/api/user/gzguoer/albumid/5334765855583692065'
try:
photo = gd_client.InsertPhotoSimple(album_url, 'blogimg',filetitle,
file_handle, content_type='image/jpeg')
img_url = photo.GetMediaURL()+"?imgmax=512"
self.response.out.write('<script type="text/javascript">
window.parent.rteGetImage("%s")</script>' % img_url)
except gdata.service.RequestError:
self.response.out.write(GooglePhotosException)上传完毕之后,直接调用该iframe他爹的javascript函数rteGetImage函数,并且把图片的外链url传输过去,哈哈,然后他爹页面把图片外链url做成一个img标签,嵌入到rich text editor的编辑区域中,并且关闭这个上传页面。哈哈,不错。下面再来一幅nb图像,看看我的摄影技术,哈哈。如上语句里面的fielname_or_handle,人家说是一个A file-like object or file name where the image/video will be read from。可惜我不太会python,所以不知道是个啥玩意。后来发现,这个东东可以使本地文件的绝对路径,哈哈。太nb了,至今我还不能获得用户选择的文件的绝对路径。。def InsertPhotoSimple(self, album_or_uri, title, summary, filename_or_handle,
content_type='image/jpeg', keywords=None)
import gdata.urlfetch*另外注意密码保护,由于本程序可以在google code上下载到,所以密码我保存到本机的bbpsw类中,然后定义一个方法getpassword得到密码,或许由更好的方法,但是我不想在每次上传图片的时候跳转到别的页面,所以还是采用这种方法了。 还遇到一个问题:就是图片上传完毕之后,服务器端不好触发客户端的javascript程序,所以我直接产生一个use it的超链接,触发javascript函数,把图片的地址做成img标签,然后加入到编辑页面中。如果不这么做,或许我需要ajax?我不想学那么多新东西啊。。。
gdata.service.http_request_handler = gdata.urlfetch
#override original http handler
...
filename = self.request.get('imgfile')
filetitle = self.request.get('imgtitle')
file_handle = StringIO.StringIO(filename)#convert string to file-like object
gd_client = gdata.photos.service.PhotosService()
gd_client.email = 'gzguoer@gmail.com'
gd_client.password = bbpsw.getpassword()
gd_client.source = 'blowblood-upload-image'
gd_client.ProgrammaticLogin()
album_url = '/data/feed/api/user/gzguoer/albumid/5334765855583692065'
try:
photo = gd_client.InsertPhotoSimple(album_url, 'blogimg',filetitle,
file_handle,content_type='image/jpeg')
template_values = {
'imgtitle':'title',
'img_url':photo.GetMediaURL(),
'response':'upload_complelted,<a href="javascript:getimgurl()">use it</a>',
}
path = os.path.join(os.path.dirname(__file__), '../templates/upload.html')
self.response.out.write(template.render(path, template_values))
except gdata.service.RequestError:
self.response.out.write(GooglePhotosException)

Recent Comments