# Uploading a local image using the API

**URL:** <https://meta.discourse.org/t/uploading-a-local-image-using-the-api/127071>\
**Category:** Development\
**Created:** [August 28, 2019, 10:37pm UTC](https://meta.discourse.org/t/uploading-a-local-image-using-the-api/127071 "2019-08-28T22:37:28Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![plongitudes](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/plongitudes/32/154728_2.png) [@plongitudes](https://meta.discourse.org/u/plongitudes)\
**Post date:** [August 28, 2019, 10:37pm UTC](https://meta.discourse.org/t/uploading-a-local-image-using-the-api/127071/1 "2019-08-28T22:37:28Z")

</div>

Hey folks,

I hope this is the right place to ask. I’m working on importing a set of data from another forum into our new Discourse instance (internal knowledge posts that we want to transition).  
I’ve got our old data nicely packed up in a bunch of JSON structures, but I’m getting hung up on uploading the various images that are related to the old posts.

I’m using the `discourse_api` gem and have had terrific success so far, though I realize that it’s incomplete. I can upload an image successfully if that image is hosted somewhere, like so:

`client.upload_file({'user_id':24,url:'http://valid.url.here/foo.jpg','synchronous':true})`

but I’m stymied when trying to upload an image that’s located on my local machine:

`client.upload_file({'user_id':24,file:'/local/path/to/image/foo.jpg','synchronous':true})`

…the above comes back with:

```plaintext
DiscourseApi::UnprocessableEntity: {"failed"=>"FAILED", 
"message"=>"undefined method 'tempfile' for 
#<String:0x00007f409d2fa398>"} from /home/user/.rvm/gems/
ruby-2.3.7/gems/discourse_api-0.36.0/lib/discourse_api/
client.rb:154:in 'handle_error'

```

I’ve poked around enough to realize that I probably need to do some base64 magic or something so that my request is properly formed (I’m also realizing that maybe the upload method for the ruby gem just can’t accommodate this type of upload (and if so, that’s fine).

Mostly I’m just looking for guidance, to see if anyone else has come up against this and to see if I’m barking up the wrong tree entirely. Thanks in advance, and all that 🙂

---

_[View the full topic](https://meta.discourse.org/t/uploading-a-local-image-using-the-api/127071)._
