[英]i want to upload images on imgbb with custom name
i want to upload images on imgbb with API with custom name.我想在 imgbb 上上传带有自定义名称的 API 的图像。
My current HTML was:我当前的 HTML 是:
<input type="text" name="img_name" id="name" accept="text/*">
<input type="file" id="input_img" accept="image/*">
<input type="submit" value="Send" onclick="fileChange()">
and My current JS was:我现在的 JS 是:
function fileChange(){
var file = document.getElementById('input_img');
var imgname = document.getElementById('name');
var form = new FormData();
form.append("image", file.files[0])
var settings = {
"url": "https://api.imgbb.com/1/upload?key=(API CODE)",
"method": "POST",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
var jx = JSON.parse(response);
console.log(jx.data.url);
});
}
when i upload image it will upload with the image default name but i want to give it custom name.当我上传图像时,它将使用图像默认名称上传,但我想给它自定义名称。
Current Result:当前结果:
https://i.stack.imgur.com/bbKZb.jpg https://i.stack.imgur.com/bbKZb.jpg
What I want:我想要的是:
https://i.stack.imgur.com/9BesZ.jpg https://i.stack.imgur.com/9BesZ.jpg
According to the api document .根据api 文件。
name (optional) The name of the file, this is automatically detected if uploading a file with a POST and multipart / form-data name (可选)文件的名称,如果使用 POST 和 multipart / form-data 上传文件,则会自动检测到该名称
You should add &name=yourName
to the url to chanage upload name您应该将
&name=yourName
添加到 url 以更改上传名称
var settings = {
"url": "https://api.imgbb.com/1/upload?key=(API CODE)&name="+ $('#name').val(),
"method": "POST",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.