0

I want to get temporary link for the uploaded file but struggling with Content type header. I have tried several combinations of Content-Type header but getting error with all. Also how can I use the function dbx.filesGetTemporaryLinks instead of this code. Please let mw know.

Here is my code:

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));
    }
Greg
  • 16,359
  • 2
  • 34
  • 44
  • What error are you getting? Also, what trouble are you having with `filesGetTemporaryLinks`? (The latter may be better suited in its own post though.) – Greg Nov 27 '16 at 21:17
  • Hello Greg , thanks for replying..the error is with Content-Type header--request body could not decode input as Json..status 400, status bad request..I tried with several combination of content-type header. – user7213078 Nov 28 '16 at 10:04

1 Answers1

1

It looks like your Content-Type and body aren't formatted properly. Here's a version that works for me:

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);
    }
})
Greg
  • 16,359
  • 2
  • 34
  • 44