0

我正在尝试将图像发送到名为 Cloudsight 的图像识别 API。我已经使用 URL 让它工作,现在正试图让它发送本地图像。问题是,它不需要任何用户交互,因为这一切都必须自动发生。我看到的答案使用 FormData,但由于它不需要用户交互,我认为我不能使用它。(除非有办法使用它来自动上传东西。)目前的代码是:

var token; //Variable for use later

//First AJAX request.
$.ajax({
  method: "POST",
  url: "https://api.cloudsightapi.com/image_requests",
  beforeSend: function(xhr) { // Authorizes the request.
    xhr.setRequestHeader("Authorization",
      "CloudSight [key]");
  },
  data: { // The data to send.
    "image_request[image]": //the image needs to go here,
    "image_request[locale]": "en-US"
  },
  success: function(msg) { // What should happen if succesful.
    console.log("It worked! :D Good POST request.");
    console.log(msg);

    token = msg.token; // Assigns the token the POST request returns to the token variable.

    get(); // Calls the function containing the GET request.
  },
  error: function(msg) { // What should happen if not succesful.
    console.log("Sorry...");
    console.log(msg);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

我所需要的只是发送本地文件;如何在没有用户交互的情况下上传图像?

4

1 回答 1

0

从技术上讲,你可以做到

netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite'); 在与 netscape 兼容的浏览器(Firefox、Mozilla、Netscape)中,它会询问用户*是否允许文件系统访问,但这不是可移植的。

*每个浏览器进程一次Q

于 2015-11-21T08:41:09.220 回答