2017-04-24 267 views
1

我有一个JavaScript应用程序发送ajax GET请求与accesstoken GoogleDrive文件的资源URL。我回来的回应可能是任何文件(作为附件/大小100MB)。我可以在我的ajax调用中轻松检测Content-Type和Content-Disposition,但是一旦检测到响应包含文件,我该如何从浏览器下载文件。从ajax下载谷歌驱动器文件得到

$.ajax({ 
      url: "https://www.googleapis.com/drive/v3/files/" + fileid + "?alt=media", 
      method: 'GET', 
      headers: 
      { 
       'Authorization': 'Bearer' +accessToken 
      },    
      success: function (response, status, request) { 
       var disp = request.getResponseHeader('Content-Disposition');    

       if (disp && disp.search('attachment') != -1) { 
        alert('We have an attachment to download'); 
       } 
       var type = request.getResponseHeader('Content-Type'); 
        alert('Attachment is of type' + type); 
      } 
     }); 
    }); 

那么,现在我该如何使用ajax请求从响应中下载文件。

回答

相关问题