-1

I'm trying upload a file using the Dropbox api in deno. But i dont know how to do that, because there is no sdk for deno. I want to try using fecth but when I upload the file, it gives a "bad request" error.

Kin Kurnia
  • 23
  • 1
  • 6
  • What did you try? Can you show your function along with a link to the place in the documentation that you used in order to implement it? – jsejcksn Oct 15 '21 at 10:12
  • Here's the api docs: https://www.dropbox.com/developers/documentation/http/documentation#files-upload – Kin Kurnia Oct 16 '21 at 16:07
  • Because there's no sdk for deno, im using the http. In deno im using fetch. – Kin Kurnia Oct 16 '21 at 16:10
  • It would help anyone who wants to give help to you if you'll provide a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). (But don't include any of your private Dropbox keys/tokens -- just use a placeholder/fake string for those). – jsejcksn Oct 17 '21 at 03:10
  • I found the problem, it turns error because the path needs '/' before the filename. – Kin Kurnia Oct 21 '21 at 06:46

1 Answers1

1

You can use the HTTP SDK.
Here is the example using fetch:

const filepath = ""
const filename = ""
const dbxAccessToken = ""
const response = await fetch(
    "https://content.dropboxapi.com/2/files/upload",
    {
      method: "POST",
      headers: {
        "Authorization":
          `Bearer ${dbxAccessToken}`,
        "Dropbox-API-Arg":
          `{"path": "/${filename}","mode": "add","autorename": true,"mute": false,"strict_conflict": false}`,
        "Content-Type": "application/octet-stream",
      },
      body: new Deno.readFile(filepath),
    },
  );

console.log(response)
Kin Kurnia
  • 23
  • 1
  • 6