繁体   English   中英

使用ajax的Javascript上传图片,无需用户交互

[英]Javascript upload image using ajax without user interaction

我正在尝试将图像发送到名为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> 

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

从技术上讲你可以做到

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

*每个浏览器进程一次

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM