简体   繁体   English

我想用自定义名称在 imgbb 上上传图片

[英]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.

相关问题 我想要上传更多图片 - i want more images upload 通过 API 删除 Imgbb 中的图像 - Deleting images in Imgbb via API 如何在 firefox 插件中使用 Javascript 将图像上传到 ImgBB API - How to upload an image to ImgBB API using Javascript in a firefox addon 使用 AJAX + Javascript 将图像上传到 PHP 网站上的 IMGBB(引导程序) - Uploading images using AJAX + Javascript to IMGBB on PHP website (Bootstrap) 我有一个 javascript 数组,想按名称调用图像 - I've got a javascript array and want to call images by name 我如何使用 imgbb 进行反应图像托管? - How Can i use imgbb for react image hosting? 当我在 html javascript 中上传文件时,我想要一个文件值或名称? - I want a file value or name when I upload a file in html javascript? 对于aws serverless,如果我想将图片上传到端点,如何获取图片文件的名称? - for aws serverless, If I want to upload picture to endpoint, How to get the name of picture file? 如何使用 base64 字符串和 axios js 将本地文件上传到 IMGBB - How to upload local files to IMGBB with base64 string with axios js 我想上传文件并制作自定义输入文件,该文件可以在所有浏览器中使用,但不能在Safari中使用 - i want to upload the file and made custom input file it's working in every browser but not in safari
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM