Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Rosemol
7 years agoExplorer | Level 3
Upload image file using fetch in js
Hi All,
I'm new to Dropbox API and I'm trying to upload image files from our website to dropbox using api. I'm using FETCH to POST data to dropbox and the file is uploading.However, the image is not getting loaded in dropbox. Below is code that I use:
fetch('https://content.dropboxapi.com/2/files/upload', {
method: 'post',
body: file1, //Base64
headers: {'Authorization': 'Bearer '+MY_TOKEN,
'Content-Type': 'application/octet-stream',
'Accept': 'application/json',
'Dropbox-API-Arg': '{"path": "/test1/test.jpg","mode": "add","autorename": false,"mute": false,"strict_conflict": false}'
}
}).then(function(response) {
console.log(response.json());
});
Please help me out with this issue. Thank you
5 Replies
- Greg-DB7 years ago
Dropbox Community Moderator
Can you clarify what you mean when you say "the image is not getting loaded in dropbox"? What are you seeing or not seeing exactly?
Also, can you share the response you get from /2/files/upload? If the call was successful, it should either contain the metadata of the uploaded file, or if it wasn't successful, an error indicating why.
- Rosemol7 years agoExplorer | Level 3
Hi Greg,
after the upload action I could see the data which i'm sending to dropbox in base64 format, but instead of seeing the image I see the data which i send.
I tried different methods and for 1 option I was successful which was sending the file object which I get from <input type="file"> value. I understand that there's no need to convert the file to base64 - Greg-DB7 years ago
Dropbox Community Moderator
Thanks for following up. I'm glad to hear you got this working as desired.
Yes, that's correct, there's no need to apply an additional encoding. Dropbox will accept whatever data you upload exactly as you upload it. So, if you want to upload an image that can be viewed later, you should just upload the unmodified raw data.
- khan_sikki6 years agoNew member | Level 2
i am getting this as response
Error in call to API function "files/upload": HTTP header "Dropbox-API-Arg": could not decode input as JSON
- Greg-DB6 years ago
Dropbox Community Moderator
khan_sikki I see you also requested help for this issue in your support ticket and included more information there, so we'll follow up with you there shortly.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!