2016-11-26 89 views
0

我想獲取上傳文件的臨時鏈接,但正在與內容類型標題爭執。我已經嘗試了幾種Content-Type標題的組合,但是卻遇到了錯誤。另外,如何使用功能dbx.filesGetTemporaryLinks而不是此代碼。請讓mw知道。Dropbox - 獲取文件的臨時鏈接

這裏是我的代碼:

var urltemp = "https://api.dropboxapi.com/2/files/get_temporary_link "; jQuery.ajax({ "url": urltemp, "method": "POST", 

    "data": { 
     "path": "filepath" 
    }, 

    "headers": { 
     "authorization": authorization, 
     'Content-Type': 'application/json; charset=utf-8' 
     //"Content-Type" :'text/plain; charset=dropbox-cors-hack' 
    }, 
    body: JSON.stringify(null), 

    success: function(data) { 
     alert("success"); 
    }, 
    error: function(response) { 
     alert("error " + JSON.stringify(response)); 
    } 
+0

你會得到什麼錯誤?另外,你使用'filesGetTemporaryLinks'有什麼麻煩? (雖然後者可能更適合在自己的帖子中) – Greg

+0

您好格雷格,感謝您的回覆..錯誤與內容類型頭 - 請求主體無法解碼輸入爲Json..status 400,狀態不良請求。 。我嘗試了幾種內容類型頭的組合。 – user7213078

回答

1

它看起來像你的Content-Type和身體格式不正確。這裏有一個適用於我的版本:

jQuery.ajax({ 
    url: 'https://api.dropboxapi.com/2/files/get_temporary_link', 
    type: 'POST', 
    processData: false, 
    data: JSON.stringify({"path": "/test.txt"}), 
    contentType: 'application/json', 
    headers: { 
     "Authorization": "Bearer <ACCESS_TOKEN>" 
    }, 
    success: function (data) { 
     console.log(data); 
    }, 
    error: function (error) { 
     console.log(error); 
    } 
})