How does Facebook share image base64 from Google App Engine - python

Im working with Google App Engine Project and I want use facebook share like this.
http://i.stack.imgur.com/uz52n.png
Im already read this
How does Facebook Sharer select Images and other metadata when sharing my URL?
but GAE cant upload physical Image, all image store in blob property in database as base64 so facebook share cant get the image :(
anyone had another idea for this problem ??

Facebook reads the og:image meta to resolve the image from your webpage. og:image don't allow data-URI image (base64 encoded).
You have to provide an image url in og:image, but with that url, you can make a workaround to simulate the behaviour of a direct image resolution and get the image from your appengine database.
This is a solution in python using Django, but the concept works for everything. The name of the image is here "key.png" where key is the key of the object containing the base64 stored image.
First, add an url to the list of django urls for your image resolution:
(r'^image/(?P<key>[^\.^/]+)\.png$', 'yourapp.views.image'),
Then in your views, get the key from the url, retrieve your object, base64 decode and send it back with the correct mimetype:
import base64
def image(request, key):
# get your object from database
f = YourImageObject.get(key)
# f.pic is the base64 encoded image
pic = f.pic[len("data:image/png;base64,"):] # remove the header
# base64 decode and respond with correct mimetype
return HttpResponse(base64.b64decode(pic), mimetype="image/png")

Related

Is it possible to change playlist image using Spotipy?

I am automating Spotify playlists by using Spotipy module and I want to edit the playlist's image. Is that possible?
Yes you can upload a playlist cover using Spotify API.
You can do it by sending a PUT request at https://api.spotify.com/v1/playlists/{playlist_id}/images this URL. Where you have to change {playlist_id} with your Spotify ID for playlist. Along with this link, you have pass the header, which must contain: Authorization, Content-Type and {playlist_id} variables. Where Authorization is the access-token, Content-Type must be image/jpeg and {playlist_id} is your unique spotify playlist id.
And the image you are uploading must be Base64 encoded JPEG image data, with maximum size of 256 KB.
If you still get stucked anywhere then please refer this official reference link of spotify
To be able to edit the image of the playlist you can use spotify mod apk on GameStoreMobi.Com as it supports image editing.

Check if file from incoming request is an image

I'm working on an application in which I need to upload images to an S3 bucket. The images come from HTTP requests inside form datas. I upload the images directly to S3 as objects (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.put_object), without saving them on my backend for security purposes.
But for other security purposes, is there a way to check if my image object is actually representing an image before uploading it to S3?
Given a bytes object, the following solution worked out for me:
def validate_image(bytes_object):
import io
from PIL import Image
try:
Image.open(io.BytesIO(bytes_array))
except OSError:
print('Not a valid image')

Get original image url from base64 Image String using Python?

Wondering can someone point me in the right direction on how to convert base64 image string to its original image URL.
My code is scraping top 5 news from google based on my search string.
Images are in one big massive base64 string. Images are printing ok on my outlook email (my code extract the news and send out an email in outlook) but when I forward that email on to different email account can't see any image but a message The linked image cannot be displayed. The file may have been moved, renamed or deleted. Just to check that, I copied the image from my outlook email and tried to paste on word document; all I can see is an empty box but no image.
any advice, please?
You can't get a URL from those. Those base64 encoded strings are fully embedded images. You could base64 decode them and save it to a file or just take the base64 encoded string an attach it to another image tag like in the incoming email.
If you have some specific code I could be of more help.

Uploading profile image with twitter api and python

I want to upload an image from my hard drive, using an html form:
Image file: <input name="imageupload" id="imageupload" type="file" />
Then I upload it to twitter with:
image=self.request.get('imageupload')
image2=base64.b64encode(image)
twitapi.Update_profile_image(image=image2)
given twitapi.Update_profile_image:
def Update_profile_image(self,image):
if not self._oauth_consumer:
raise TwitterError("The twitter.Api instance must be authenticated.")
url = '%s/account/update_profile_image.json' % (self.base_url)
data = {'image':image}
json = self._FetchUrl(url, post_data=data)
data = self._ParseAndCheckTwitter(json)
return data
Given _FetchUrl from twitter-api
I always get
TwitterError: There was a problem with your picture. Probably too big.
Any ideas whee it comes from? Thanks!
To submit ah image correctly via a form, you have to include
enctype="multipart/form-data"
eg
<form enctype="multipart/form-data" action='/' method="POST">
Twitter RESTful API Document is not correct.
Do NOT encode image binary to base64!
Remove base64 encode section from your source.
If you encode image binary to base64 string, twitter api says
"... was a problem with your picture probably too big. (...) (code 131)"
As per the documentation, your image:
Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size.
So make sure your image fits within these constraints. Maybe you need to scale down your image, or convert it to a different format.
If that doesn't work, try uploading another very tiny image that meets the constraints above. At least you can then verify whether or not the problem lays with the particular image you are using.
Perhaps the image you are receiving via the form upload is already base64 encoded ?
You are then applying a double encoding which could confuse the validation on the twitter server side because it would be unable to find a typical image header in your uploaded file.

Client side s3 upload and returning the public url of the image

I am writing a client side image uploader library for python. I need to upload an image to Amazon S3 and return the public URL of the image. I can do this using BOTO however I have to share my Secret Key which is not the correct way of doing it. As an alternative, I can use Browser upload using Amazon's POST request but that doesn't give me access to the image's public URL. How do I solve this conundrum?
I have the same issue. The only thing I have found is to make the image public on save and later use:
item.image.url.split('?')[0]
to get the URL.
How about using the urlparse module to get the URL without the query parameters?

Categories