Upload file using input tag(without rails/html form) and paperclip in rails - ajax

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.

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.

Related

Extract image link from TinyMCE in Laravel

I'm making an image sitemap for my site I'm trying to extract the image link from the post and I'm using the TinyMCE text editor Need Help pls.
I use this code but the problem is I do this in the controller and I can't do it in the view This code being in the Controller leads to two problems, first, that I will not be able to all the images for one post, but I have to fetch the images of all posts together at once. The second thing or the second problem is that this code extracts the images twice: the link I want and the link inside So I want a solution so that I can extract images for one post
Below is a picture of the code in the controller

Send javascript variable to wordpress post on save moment

I developed a plugin that make a html list dinamycally, based on javascript change events of a select element. I need to save that post with this new list items. I think that´s necessary send this list items via ajax maybe with (wp_localize_script). How to do this?
I think you can create hidden input tag in dynamically using javascript and pass this hidden element to using post method using ajax to use in php post saving.

How to control the dimension of an image during the upload with symfony2

i check in the doc and everywhere i could but i didn't find any solution.
So i have a form and i upload an image in this form. I would like an error message if user is submiting a too large image or a too tall one. I need to do this for a proper display for my image.
I would like if possible do this with #assert but i dont think it's possible so i can add a validation.yml file if it's needed but it has to be check on the client-side
Thx if you have any clue to do this !

submit additional form data with jquery file upload and rails 3

I have been trying to set up the tutorial, https://github.com/blueimp/jQuery-File-Upload/wiki/How-to-submit-additional-Form-Data with rails 3. However I am slightly confused about how Form Data works with Rails Object. From my research it seems that Form Data with serializeData returns an array. However, I am totally lost about what to do after that.
I am wondering how do I use data.FormData and put it in my rails object. For example I have an art model in Rails that file upload will upload a picture to. What can i put in my controller under create so that the title of the art object correspond to the title under the label in td class="title" Title: input name="title[]" required /label /td "Thanks.
Regards,
Kane

CodeIgniter santizing POST values

I have a text area in which I am trying to add youtube embed code and other HTML tags. $this->input->post is converting the <iframe> tags to < and > respectively but not the <h1> and <h2> tags.
Any idea how I can store these values?
If you only have a small number of forms that you need to allow iframes in, I would just write a function to restore the iframe (while validating that it's a valid YouTube embed code).
You can also turn off global_xss_filtering in your config (or not implement it if you're using it), but that's not the ideal solution (turning off all of your security to get one thing to work is generally a horrible idea).
$config['global_xss_filtering'] = FALSE;
To see all of the tags that get filtered out, look in the CI_Input class and search for the '$naughty' variable. You'll see a pipe-delimited list (don't change anything in this class).
Why don't you avoid CIs auto sanitizing and use something like htmlspecialchars($_POST['var']); ? Or make a helper function for sanitizing youtube urls...
Or you could either just ask for the video ID code or parse the code from what you are getting.
This would let you use both the URL or the embed code.
Also storing just the ID takes less space in you database, and you could write a helper function to output the embed code/url.
In this case, use $_POST instead of $this->input->post to get the original text area value, and then use HTML Purifier to clean the contents without losing the <iframe> tag you want.
You will need to check HTML Purifier documentation for details. Please, check this specific documentation page about "Embedding YouTube Videos".

Resources