簡體   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