Put request in POSTMAN, laravel - laravel

I am using the postman for an api creation for my laravel project.
I have made POST requesting for uploading the video but now I am trying to make a PUT request.Other things are being updated in the table using it like title and name but I am not able to use any option to upload the file(image) for PUT request.And if I use form-data then nothings happens in this case.

You should be required the following changes.
1) In Headers
The Content-type field has been set as multipart/form-data in Headers.
2) Choose the File option instead of text from the dropdown on the right side.
3) add _method: PUT in form-data

For PUT calls, try adding data in x-www-form-urlencoded

You need to use POST method for file uploading. cause PUT method not supporting file uploading. here is issue in official github repo of laravel. you can see here reply from laravel

If using formdata, add this Key: _method and value: PUT, in the formdata. Then use POST as the request.
NB: This also supports Image uploading, give the key the name you want, then change text to File

select form-data and select file type from the key box and change Text to File.

In postman, you can simply send a PUT request by changing the Request method near URL Bar.
For uploading files, select "form-data" as input in postman then you will see a panel to enter key-value pairs. Initially, you will notice that both the fields take text as input.
To upload a file from this panel, in the left box (where you are supposed to enter key name) check the rightmost corner. You can see the type of the box and then change it to file.
As soon as you change the key type, the value field will ask you to upload a file.
Edit 1:
You can see in the screenshot here, where you need to change it from "Text" to "File"

What you need to do is just:
Select POST method
Set _method = PUT in the body of Form-data

Related

How to add form fields to image preview?

In vue-filepond, I can drag or select files and they process fine, but I want to be able to submit user entered data along with each image. For example, they may want to tag the image or enter a title, etc..
I can't find any documentation on how to do this?
You can use the file.setMetadata method (https://pqina.nl/filepond/docs/patterns/api/file/#methods) to add metadata to each file, each upload will contain a File object and a JSON object (the JSON object will contain the metadata).

TinyMCE4 `image_list` external url

I am trying to get TinyMCE 4's image_list to work with a URL returning JSON data as specified in the example here.
I have setup a GET endpoint http://demo.com/media on my server which gives back a JSON response consisting of a list of objects with their title and value attributes set, for example:
[{"title":"demo.jpg","value":"http://demo.com/demo.jpg"}]
I have also specified the option image_list: "http://demo.com/media" when initializing the plugin.
However, when I click the image icon in the toolbar, nothing pops up. All I can see in the network tab is an OPTIONS request with status 200, but then nothing. The GET request I was expecting never happens.
What is the correct way of using image_list in TinyMCE 4? Also, does anyone have a working demo example? I couldn't find anything.
It is somewhat hard to say what the issue is without seeing the exact data your URL is returning. I have created a TinyMCE Fiddle to show (in general) how this is supposed to work:
http://fiddle.tinymce.com/pwgaab
There is a JavaScript variable at the top (pretendFetchedData) that simulates what you would grab from the server (an array of JavaScript objects) and that is referenced via image_list.
If you enter your URL (http://demo.com/media) into a browser window what is returned? Are you sure its an array of JavaScript objects?
I have the identical problem. No matter what I do with the detail of the format (e.g. putting quotes round title and value), nothing happens.
I guess the only way (for me anyway) is to insert the list into the script with php before sending the web page.

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.

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

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.

ASP.NET MVC Image form validation

I'm running into an issue on a particular form.
If the form is submitted and there is an error with the form (maybe I forgot to fill in a required field), then the form reloads with the errors as it's supposed to. However, any image you had previously selected, disappears and needs to be reselected.
Before submitting form with errors:
After submitting form with errors:
This is the HTML tag being used:
<input type="file" accept="image/*" id="Image" name="Image"/>
What I need is for the image selector to still maintain the selected image between submits. Is there a good way to do this? Is there a way to save the file path to the session perhaps and fill it into the element again?
Browsers will not allow file upload fields to be restored automatically as a security measure. To prevent losing the file from validation, either perform all validation on the client side (though you should always validate again on the server) so the form is never submitted until everything is correct or you have to grab the file(s) that are submitted the first time and hold on to them until the form finally comes through with all validation completed.
In this second case you have a couple options:
Save the contents somewhere and return a unique ID pointer to be held in a hidden field when you return the form. You should also consider putting a visible label that shows what file has already been uploaded. You will have to clean up uploads periodically from users who give up and come back later (and thus won't be submitting a form with that correlation ID for you to match up the upload).
Base64 encode the contents of the uploaded file and return that to the view in a hidden field. This is more bandwidth intensive but it doesn't require you to store a file on your server that may never be correlated to a proper form. You might also be able to display that same image in the returned view since I believe you can specify a Base64 encoded image as the source for an image tag (or maybe CSS attribute). This might be browser specific.
As long as your file uploads are limited in size (100kb for instance) option 2 is my favored approach. It's not much bigger than all the modern JavaScript libraries that are included in a page and is a better experience for the user while leaving your server dumb of sessions, cleanup or excessive processing.
Edit: Many sites that allow uploading of images also provide validation on file size and kick it back if it's oversized. In this case the user has feedback that their asset has not been stored and you're free from having to encode and return it.
Edit 2:
Here's a post about browsers marking the file upload control value field as read-only and preventing this from being modified by JavaScript (it can only be modified by direct user action).
And here's a SO comment about using Base64 encoded image in HTML directly. The question asker is looking for a way to put the data in a separate file but this isn't what you want. The 'this works' portion is what I was referring to in Option 2 above.
I think you can use the hidden field and display the file selected in the label. When after validation get the content of the file and save it in the Session or some temp place . Then while showing the page so on the label the file path what user has selected earlier and update the same in the hidden field . If the user submit the form again check first if the file is NULL but hidden field value is there , it means you have save the file earlier, If the path is different from the hidden field you may have to get the file content again.
Just saving the path will not help you have to save the file stream uploaded first time . I think if your user will be delight with not loading the file again you have to pay something from your server resource :)
The only way you can do this is to provide validation on client side. It is because submit to server "sends" already a form, and resend it back with errors. As it was pointed out in comment, the file is cleared because of security (thanks Eric)
To do client side validation in MVC 3 you can use unobstuctive jquery validation. To do this just add in web.config:
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

Resources