0

I am a kind of new on ROR, I want to upload an image using simple input tag and don't want to use form for that. The basic functionality of Paperclip is known to me. If I am not wrong then the format of object that is being passed to save image is :

"image_object"=>
  [#< ActionDispatch::Http::UploadedFile:0xb5ad25f4
    @content_type="image/gif",
    @headers=
     "Content-Disposition: form-data; name=\"pic[]\"; filename=\"test.gif\"\r\nContent-Type: image/gif\r\n",
    @original_filename="test.gif",
    @tempfile=#<File:/tmp/RackMultipart20131112-17750-1lprijc>>]

I want to upload image using the following steps: 1. Using Jquery, I want to fetch the appropriate details(file parameter) of selected image in input tag and send those using Jquery/ajax. 2. By passing that parameters to rails controller I want to use those details to generate an object(as sample shown above) that can be used to save Image in my application.

My questions are: 1. which Jquery method should I use and what are the parameters that are necessary to generate the image object? 2. On controller side, how to generate Image Object using those details?

Thanks in advance.

2
  • Are you trying to upload file through RESTApi ? Commented Nov 13, 2013 at 6:53
  • Yes I am doing this... Commented Nov 13, 2013 at 7:18

1 Answer 1

1

I'm not sure if I understood your question right. But based on the details you provided there are many options you can go for.

The simplest one is as follows:

Just add :remote => true to the rails form and submit the form and on the controller side you can create the object.

But if you want to be able to upload an image through a REST API then this link should help.

You can visit the SO question as well here which describes exactly what u want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.