Last active
September 12, 2017 04:38
-
-
Save marcelo-ribeiro/46d3906d330f4025aa35f4d4cfecb8e1 to your computer and use it in GitHub Desktop.
WP REST API Upload Image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var settings = { | |
"async": true, | |
"crossDomain": true, | |
"url": "http://www.marcelo-ribeiro.tk/wp-json/wp/v2/media/48", | |
"method": "POST", | |
"headers": { | |
"authorization": "Basic bWFyY2Vsb3JpYmVpcm86QDg1ODM1OTU0Iw==", | |
"content-type": "application/json" | |
}, | |
"processData": false, | |
"data": "{\n\t\"post\": 1,\n\t\"author\": 1,\n\t\"title\": \"Imagem carro\"\n}" | |
} | |
$.ajax(settings).done(function (response) { | |
console.log(response); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var form = new FormData(); | |
form.append("file", $('input#file')[0].files[0]); | |
form.append("title", "Minha imagem"); | |
form.append("post", "1"); | |
form.append("author", "1"); | |
var settings = { | |
"async": true, | |
"crossDomain": true, | |
"url": "http://www.marcelo-ribeiro.tk/wp-json/wp/v2/media", | |
"method": "POST", | |
"headers": { | |
"authorization": "Basic bWFyY2Vsb3JpYmVpcm86QDg1ODM1OTU0Iw==", | |
"content-disposition": "attachment; filename=imagem_teste.jpg" | |
}, | |
"processData": false, | |
"contentType": false, | |
"mimeType": "multipart/form-data", | |
"data": form | |
} | |
$.ajax(settings).done(function (response) { | |
console.log(response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment