开发者

Django:How to let 3rd party sites access images on your server.(limited access i.e. only to that folder)

开发者 https://www.devze.com 2023-04-09 09:40 出处:网络
I am working in Django.I am trying to connect my website to Facebook. What i want to do is 1)Send post_data

I am working in Django.I am trying to connect my website to Facebook. What i want to do is

1)Send post_data

post_data = [('access_token',access_token), ('message', message), ('link', some_link),('picture',internal_server_path_of_image)
开发者_运维知识库

2)urllib2.urlopen(graph_url, urllib.urlencode(post_data))

What this should do is post that data on the facebook profile of a user. But i am unable to access "internal_server_path_of_image". Is there anyway in which i can make a particular folder on my server available to the site ? i.e. the images on that folder should be accessible from outside. for e.g. I have folder site_name/project/images/photos.png on the server some_server.dreamhost.com/site_name/project/images/photos.png. Now i want to access this image somehow.

Is the question clear ? or do I need to add a few things ? Any help will be highly appreciated.


I have come with a solution. As people had pointed out that the imagefield gives us the url of the image. That was true, what i am doing now is passing that url. At that url i have written a controller method. This method simply renders the image and returns it. This gives access to the facebook api to get the required image from my server.

def test(request,name): 
   name = str(name)+".jpg" 
   url = "Users/admin/workspace/bolt/templates/media/images/photos/" 
   full = url+name image_data = open(full, "rb").read() 
   return HttpResponse(image_data, mimetype="image/png")

Hope this helps others

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号