def upload_pic(self, upload_pic): if not self.is_authenticated: raise PicplzError( "uploading a new pic requires an authenticated API instance") parameters = upload_pic.get_parameters() form = MultiPartForm() form.add_field('oauth_token', self.authenticator.access_token.to_string()) for key in parameters.keys(): form.add_field(key, parameters[key]) # Add a fake file form.add_file('file', upload_pic.file.name, fileHandle=upload_pic.file) # Build the request request = urllib2.Request(self.upload_endpoint) request.add_header( 'User-agent', 'python-picplz: https://github.com/ejesse/python-picplz') body = str(form) request.add_header('Content-type', form.get_content_type()) request.add_header('Content-length', len(body)) request.add_data(body) response = urllib2.urlopen(request) response_text = response.read() if self.print_json: print response_text self.__check_for_picplz_error__(response_text) return response_text
def upload_pic(self, upload_pic): if not self.is_authenticated: raise PicplzError("uploading a new pic requires an authenticated API instance") parameters = upload_pic.get_parameters() form = MultiPartForm() form.add_field('oauth_token', self.authenticator.access_token.to_string()) for key in parameters.keys(): form.add_field(key,parameters[key]) # Add a fake file form.add_file('file', upload_pic.file.name, fileHandle=upload_pic.file) # Build the request request = urllib2.Request(self.upload_endpoint) request.add_header('User-agent', 'python-picplz: https://github.com/ejesse/python-picplz') body = str(form) request.add_header('Content-type', form.get_content_type()) request.add_header('Content-length', len(body)) request.add_data(body) response = urllib2.urlopen(request) response_text = response.read() if self.print_json: print response_text self.__check_for_picplz_error__(response_text) return response_text
def upload_pic_url(self,oauth_token, upload_pic_url): #parameters = upload_pic.get_parameters() parameters= {} #parameters['suppress_sharing'] = 1 form = MultiPartForm() sb=StringIO(urllib2.urlopen(upload_pic_url).read()) form.add_field('oauth_token', oauth_token) #form.add_field('oauth_token', self.authenticator.access_token.to_string()) for key in parameters.keys(): form.add_field(key,parameters[key]) # Add a fake file form.add_file('file', '%s' % uuid.uuid4(), fileHandle=sb) # Build the request request = urllib2.Request(self.upload_endpoint) body = str(form) logging.info('body: %s' %body) request.add_header('Content-type', form.get_content_type()) request.add_header('Content-length', len(body)) request.add_data(body) response = urllib2.urlopen(request) response_text = response.read() if self.print_json: print response_text self.__check_for_picplz_error__(response_text) return response_text