{"id":74,"date":"2008-11-06T10:40:51","date_gmt":"2008-11-05T23:40:51","guid":{"rendered":"http:\/\/spiffystores.com.au\/blog\/?p=74"},"modified":"2021-09-01T07:00:44","modified_gmt":"2021-08-31T21:00:44","slug":"how-to-fake-an-uploaded-file","status":"publish","type":"post","link":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/","title":{"rendered":"How to Fake an Uploaded File"},"content":{"rendered":"\n<p>Our store software contains an extensive set of routines for processing uploaded images and resizing them into various image sizes. We&#8217;ve recently been adding some code to support a bulk import function and it&#8217;s become necessary to somehow fake uploading a file, given a specific URL for an image.<\/p>\n\n\n\n<p>The basic plan is to use Net::HTTP to connect to the remote server and grab the image and save it in a temporary file. It turns out that Rails contains a UploadedTempfile class which is a subclass of Tempfile, and this is used by the CGI routines to handle any uploaded files.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>So all we need to do is create our own instance of UploadedTempfile, set some attributes and then pass it along to our existing routines as if it were a real uploaded file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"ruby\" class=\"language-ruby line-numbers\">uri = URI.parse(image_url)\nimage_file_name = File.basename(uri.path) # Extract the file name\nimage_file = nil\nbegin\n  timeout(10) do\n    Net::HTTP.start(uri.host, uri.port) do |http|\n      resp = http.get(uri.path)\n      image_file = ActionController::UploadedTempfile.new(image_file_name)\n      image_file.binmode\n      image_file.write(resp.body)\n      image_file.original_path = image_file_name\n      image_file.rewind\n    end\n  end\nrescue TimeoutError\n  raise \"Timeout connecting to #{uri.host}\"\nend\n<\/code><\/pre>\n\n\n\n<p>There are a few things that need to be set up, so that the fake upload file works properly.<\/p>\n\n\n\n<p>The file is set to binary mode with<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>image_file.binmode<\/p><\/blockquote>\n\n\n\n<p>The original file name is set with<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>image_file.original_path = image_file_name<\/p><\/blockquote>\n\n\n\n<p>A content type attribute can also be set with<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>image_file.content_type<\/p><\/blockquote>\n\n\n\n<p>but we don&#8217;t use this attribute, so it&#8217;s not set here.<\/p>\n\n\n\n<p>Finally we rewind the file so that we can read it later on in the image processing routines. When we&#8217;re finished with the temporary file, we can delete it with a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>image_file.close!<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Our store software contains an extensive set of routines for processing uploaded images and resizing them into various image sizes. We&#8217;ve recently been adding some code to support a bulk import function and it&#8217;s become necessary to somehow fake uploading &hellip; <a href=\"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,1],"tags":[14,12,11,13,10],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-geek-stuff","category-show-all","tag-file","tag-rails","tag-ruby","tag-uploaded","tag-uploaded-tempfile"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.8 - aioseo.com -->\n\t<meta name=\"description\" content=\"Our store software contains an extensive set of routines for processing uploaded images and resizing them into various image sizes. We&#039;ve recently been adding some code to support a bulk import function and it&#039;s become necessary to somehow fake uploading a file, given a specific URL for an image. The basic plan is to use\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Brian\"\/>\n\t<meta name=\"google-site-verification\" content=\"IZJrt3makBt-M2quuWWH3u_03zWqYFgBUMNHrhv4Nsc\" \/>\n\t<meta name=\"keywords\" content=\"file,rails,ruby,uploaded,uploaded tempfile,geek stuff,show all\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.8\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Spiffy Stores Blog | Checkout - The Spiffy Stores Blog\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"How to Fake an Uploaded File | Spiffy Stores Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Our store software contains an extensive set of routines for processing uploaded images and resizing them into various image sizes. We&#039;ve recently been adding some code to support a bulk import function and it&#039;s become necessary to somehow fake uploading a file, given a specific URL for an image. The basic plan is to use\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.spiffystores.com.au\/blog\/wp-content\/uploads\/2021\/05\/spiffy-stores-logo-large.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.spiffystores.com.au\/blog\/wp-content\/uploads\/2021\/05\/spiffy-stores-logo-large.png\" \/>\n\t\t<meta property=\"og:image:width\" content=\"1672\" \/>\n\t\t<meta property=\"og:image:height\" content=\"1672\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2008-11-05T23:40:51+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2021-08-31T21:00:44+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/spiffystores\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@spiffystores\" \/>\n\t\t<meta name=\"twitter:title\" content=\"How to Fake an Uploaded File | Spiffy Stores Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Our store software contains an extensive set of routines for processing uploaded images and resizing them into various image sizes. We&#039;ve recently been adding some code to support a bulk import function and it&#039;s become necessary to somehow fake uploading a file, given a specific URL for an image. The basic plan is to use\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@spiffystores\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.spiffystores.com.au\/blog\/wp-content\/uploads\/2021\/05\/spiffy-stores-logo-large.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#article\",\"name\":\"How to Fake an Uploaded File | Spiffy Stores Blog\",\"headline\":\"How to Fake an Uploaded File\",\"author\":{\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/author\\\/brian\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/spiffy-stores-logo-large.png\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/#articleImage\",\"width\":1672,\"height\":1672,\"caption\":\"Spiffy Stores\"},\"datePublished\":\"2008-11-06T10:40:51+11:00\",\"dateModified\":\"2021-09-01T07:00:44+10:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#webpage\"},\"articleSection\":\"Geek stuff, Show All, file, rails, ruby, uploaded, uploaded tempfile\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/category\\\/show-all\\\/#listItem\",\"name\":\"Show All\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/category\\\/show-all\\\/#listItem\",\"position\":2,\"name\":\"Show All\",\"item\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/category\\\/show-all\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#listItem\",\"name\":\"How to Fake an Uploaded File\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#listItem\",\"position\":3,\"name\":\"How to Fake an Uploaded File\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/category\\\/show-all\\\/#listItem\",\"name\":\"Show All\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/#organization\",\"name\":\"Spiffy Stores\",\"description\":\"Checkout - The Spiffy Stores Blog\",\"url\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/\",\"telephone\":\"+611300727334\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/spiffy-stores-logo-large.png\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#organizationLogo\",\"width\":1672,\"height\":1672,\"caption\":\"Spiffy Stores\"},\"image\":{\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#organizationLogo\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/spiffystores\",\"https:\\\/\\\/twitter.com\\\/spiffystores\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/author\\\/brian\\\/#author\",\"url\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/author\\\/brian\\\/\",\"name\":\"Brian\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e353f9d9a739a33b0eeee1e15ec3d629ccee44014b28e583950ffff7028c26bb?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Brian\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#webpage\",\"url\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/\",\"name\":\"How to Fake an Uploaded File | Spiffy Stores Blog\",\"description\":\"Our store software contains an extensive set of routines for processing uploaded images and resizing them into various image sizes. We've recently been adding some code to support a bulk import function and it's become necessary to somehow fake uploading a file, given a specific URL for an image. The basic plan is to use\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/2008\\\/11\\\/06\\\/how-to-fake-an-uploaded-file\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/author\\\/brian\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/author\\\/brian\\\/#author\"},\"datePublished\":\"2008-11-06T10:40:51+11:00\",\"dateModified\":\"2021-09-01T07:00:44+10:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/\",\"name\":\"Spiffy Stores Blog\",\"description\":\"Checkout - The Spiffy Stores Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.spiffystores.com.au\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"How to Fake an Uploaded File | Spiffy Stores Blog","description":"Our store software contains an extensive set of routines for processing uploaded images and resizing them into various image sizes. We've recently been adding some code to support a bulk import function and it's become necessary to somehow fake uploading a file, given a specific URL for an image. The basic plan is to use","canonical_url":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/","robots":"max-image-preview:large","keywords":"file,rails,ruby,uploaded,uploaded tempfile,geek stuff,show all","webmasterTools":{"google-site-verification":"IZJrt3makBt-M2quuWWH3u_03zWqYFgBUMNHrhv4Nsc","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#article","name":"How to Fake an Uploaded File | Spiffy Stores Blog","headline":"How to Fake an Uploaded File","author":{"@id":"https:\/\/www.spiffystores.com.au\/blog\/author\/brian\/#author"},"publisher":{"@id":"https:\/\/www.spiffystores.com.au\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/www.spiffystores.com.au\/blog\/wp-content\/uploads\/2021\/05\/spiffy-stores-logo-large.png","@id":"https:\/\/www.spiffystores.com.au\/blog\/#articleImage","width":1672,"height":1672,"caption":"Spiffy Stores"},"datePublished":"2008-11-06T10:40:51+11:00","dateModified":"2021-09-01T07:00:44+10:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#webpage"},"isPartOf":{"@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#webpage"},"articleSection":"Geek stuff, Show All, file, rails, ruby, uploaded, uploaded tempfile"},{"@type":"BreadcrumbList","@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.spiffystores.com.au\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.spiffystores.com.au\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.spiffystores.com.au\/blog\/category\/show-all\/#listItem","name":"Show All"}},{"@type":"ListItem","@id":"https:\/\/www.spiffystores.com.au\/blog\/category\/show-all\/#listItem","position":2,"name":"Show All","item":"https:\/\/www.spiffystores.com.au\/blog\/category\/show-all\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#listItem","name":"How to Fake an Uploaded File"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.spiffystores.com.au\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#listItem","position":3,"name":"How to Fake an Uploaded File","previousItem":{"@type":"ListItem","@id":"https:\/\/www.spiffystores.com.au\/blog\/category\/show-all\/#listItem","name":"Show All"}}]},{"@type":"Organization","@id":"https:\/\/www.spiffystores.com.au\/blog\/#organization","name":"Spiffy Stores","description":"Checkout - The Spiffy Stores Blog","url":"https:\/\/www.spiffystores.com.au\/blog\/","telephone":"+611300727334","logo":{"@type":"ImageObject","url":"https:\/\/www.spiffystores.com.au\/blog\/wp-content\/uploads\/2021\/05\/spiffy-stores-logo-large.png","@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#organizationLogo","width":1672,"height":1672,"caption":"Spiffy Stores"},"image":{"@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#organizationLogo"},"sameAs":["https:\/\/www.facebook.com\/spiffystores","https:\/\/twitter.com\/spiffystores"]},{"@type":"Person","@id":"https:\/\/www.spiffystores.com.au\/blog\/author\/brian\/#author","url":"https:\/\/www.spiffystores.com.au\/blog\/author\/brian\/","name":"Brian","image":{"@type":"ImageObject","@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/e353f9d9a739a33b0eeee1e15ec3d629ccee44014b28e583950ffff7028c26bb?s=96&d=mm&r=g","width":96,"height":96,"caption":"Brian"}},{"@type":"WebPage","@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#webpage","url":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/","name":"How to Fake an Uploaded File | Spiffy Stores Blog","description":"Our store software contains an extensive set of routines for processing uploaded images and resizing them into various image sizes. We've recently been adding some code to support a bulk import function and it's become necessary to somehow fake uploading a file, given a specific URL for an image. The basic plan is to use","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.spiffystores.com.au\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/#breadcrumblist"},"author":{"@id":"https:\/\/www.spiffystores.com.au\/blog\/author\/brian\/#author"},"creator":{"@id":"https:\/\/www.spiffystores.com.au\/blog\/author\/brian\/#author"},"datePublished":"2008-11-06T10:40:51+11:00","dateModified":"2021-09-01T07:00:44+10:00"},{"@type":"WebSite","@id":"https:\/\/www.spiffystores.com.au\/blog\/#website","url":"https:\/\/www.spiffystores.com.au\/blog\/","name":"Spiffy Stores Blog","description":"Checkout - The Spiffy Stores Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.spiffystores.com.au\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Spiffy Stores Blog | Checkout - The Spiffy Stores Blog","og:type":"article","og:title":"How to Fake an Uploaded File | Spiffy Stores Blog","og:description":"Our store software contains an extensive set of routines for processing uploaded images and resizing them into various image sizes. We've recently been adding some code to support a bulk import function and it's become necessary to somehow fake uploading a file, given a specific URL for an image. The basic plan is to use","og:url":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/","og:image":"https:\/\/www.spiffystores.com.au\/blog\/wp-content\/uploads\/2021\/05\/spiffy-stores-logo-large.png","og:image:secure_url":"https:\/\/www.spiffystores.com.au\/blog\/wp-content\/uploads\/2021\/05\/spiffy-stores-logo-large.png","og:image:width":1672,"og:image:height":1672,"article:published_time":"2008-11-05T23:40:51+00:00","article:modified_time":"2021-08-31T21:00:44+00:00","article:publisher":"https:\/\/www.facebook.com\/spiffystores","twitter:card":"summary","twitter:site":"@spiffystores","twitter:title":"How to Fake an Uploaded File | Spiffy Stores Blog","twitter:description":"Our store software contains an extensive set of routines for processing uploaded images and resizing them into various image sizes. We've recently been adding some code to support a bulk import function and it's become necessary to somehow fake uploading a file, given a specific URL for an image. The basic plan is to use","twitter:creator":"@spiffystores","twitter:image":"https:\/\/www.spiffystores.com.au\/blog\/wp-content\/uploads\/2021\/05\/spiffy-stores-logo-large.png"},"aioseo_meta_data":{"post_id":"74","title":null,"description":null,"keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":{"locations":{"business":{"name":"","businessType":"","image":"","areaServed":"","urls":{"website":"","aboutPage":"","contactPage":""},"address":{"streetLine1":"","streetLine2":"","zipCode":"","city":"","state":"","country":"","addressFormat":"#streetLineOne\n#streetLineTwo\n#city, #state #zipCode"},"contact":{"email":"","phone":"","phoneFormatted":"","fax":"","faxFormatted":""},"ids":{"vat":"","tax":"","chamberOfCommerce":""},"payment":{"priceRange":"","currenciesAccepted":"","methods":""}}},"openingHours":{"useDefaults":true,"show":true,"alwaysOpen":false,"use24hFormat":false,"timezone":"","labels":{"closed":"","alwaysOpen":""},"days":{"monday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"tuesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"wednesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"thursday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"friday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"saturday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"sunday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"}}}},"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-04-04 21:15:48","updated":"2025-06-04 08:03:58","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.spiffystores.com.au\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.spiffystores.com.au\/blog\/category\/show-all\/\" title=\"Show All\">Show All<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tHow to Fake an Uploaded File\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.spiffystores.com.au\/blog"},{"label":"Show All","link":"https:\/\/www.spiffystores.com.au\/blog\/category\/show-all\/"},{"label":"How to Fake an Uploaded File","link":"https:\/\/www.spiffystores.com.au\/blog\/2008\/11\/06\/how-to-fake-an-uploaded-file\/"}],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pgk4DF-1c","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":1,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":3226,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/posts\/74\/revisions\/3226"}],"wp:attachment":[{"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}