{"id":7604,"date":"2015-09-14T17:16:30","date_gmt":"2015-09-14T17:16:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/09\/14\/scrapy-image-download-how-to-use-custom-filename-open-source-projects-scrapy-scrapy\/"},"modified":"2015-09-14T17:16:30","modified_gmt":"2015-09-14T17:16:30","slug":"scrapy-image-download-how-to-use-custom-filename-open-source-projects-scrapy-scrapy","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/09\/14\/scrapy-image-download-how-to-use-custom-filename-open-source-projects-scrapy-scrapy\/","title":{"rendered":"Scrapy image download how to use custom filename-open source projects scrapy\/scrapy"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9153803872ee918f63cc0eebd112aaa2?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>ArtStack<\/strong><\/p>\n<p>I rewrite the code, changing, in thumb_path def, &#8220;response.&#8221; by &#8220;request.&#8221;. If no, it won&#8217;t work because &#8220;response is set to None&#8221;.<\/p>\n<pre><code>class MyImagesPipeline(ImagesPipeline):\n\n    #Name download version\n    def file_path(self, request, response=None, info=None):\n        #item=request.meta['item'] # Like this you can use all from item, not just url.\n        image_guid = request.url.split('\/')[-1]\n        return 'full\/%s' % (image_guid)\n\n    #Name thumbnail version\n    def thumb_path(self, request, thumb_id, response=None, info=None):\n        image_guid = thumb_id + request.url.split('\/')[-1]\n        return 'thumbs\/%s\/%s.jpg' % (thumb_id, image_guid)\n\n    def get_media_requests(self, item, info):\n        #yield Request(item['images']) # Adding meta. Dunno how to put it in one line :-)\n        for image in item['images']:\n            yield Request(image)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ArtStack I rewrite the code, changing, in thumb_path def, &#8220;response.&#8221; by &#8220;request.&#8221;. If no, it won&#8217;t work because &#8220;response is set to None&#8221;. class MyImagesPipeline(ImagesPipeline): #Name download version def file_path(self, request, response=None, info=None): #item=request.meta[&#8216;item&#8217;] # Like this you can use all from item, not just url. image_guid = request.url.split(&#8216;\/&#8217;)[-1] return &#8216;full\/%s&#8217; % (image_guid) #Name thumbnail [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7604","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7604"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7604\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}