We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
varunvyas5678
3 years agoExplorer | Level 3
Error : POST https://content.dropboxapi.com/2/files/upload_session/append_v2 400 (Bad Request)
Getting error while appending blobs to session using 'https://content.dropboxapi.com/2/files/upload_session/append_v2' in Salesforce LWC JS:
uploadFile(event){
var file = event.target.files[0];
console.log(file);
var dropboxToken = 'AccessToken'
console.log('FileName:'+file.name);
const maxBlob = 8 * 1000 * 1000;
var workItems = [];
var offset = 0;
var sessionID;
// Slice the file into chunks for upload session
while (offset < file.size) {
var chunkSize = Math.min(maxBlob, file.size - offset);
workItems.push(file.slice(offset, offset + chunkSize));
offset += chunkSize;
}
const task = workItems.reduce((acc, blob, idx, items) => {
if (idx == 0) {
// Start multipart upload of file
return acc.then(function() {
return fetch(dbxURL_start, {
"method": "post",
"headers": {
"Authorization" : "Bearer "+dropboxToken,
"Content-Type": "application/octet-stream",
"Dropbox-API-Arg": "{\"close\":false}"
},
"body": blob
})
.then((response) => {
sessionID = response.session_id;
})
.catch(err => console.log("[ERROR] UPLOAD_SESSION_START : " + err));
})
} else if (idx < items.length-1) {
// Append part to the upload session
return acc.then(function(sessionID) {
return fetch(dbxURL_append, {
"method": "post",
"headers": {
"Authorization" : "Bearer "+dropboxToken,
"Content-Type": "application/octet-stream",
"Dropbox-API-Arg": "{\"cursor\": {\"session_id\": \"" + sessionID + "\",\"offset\":\"" + (idx * maxBlob) + "\"},\"close\":false}"
},
"body": blob
})
.then(() => sessionID)
.catch(err => console.log("[ERROR] UPLOAD_SESSION_APPEND : " + err));
})
} else {
// Last chunk of data, close upload session
return acc.then(function(sessionID) {
return fetch(dbxURL_finish, {
"method": "post",
"headers": {
"Authorization" : "Bearer "+dropboxToken,
"Content-Type": "application/octet-stream",
"Dropbox-API-Arg": "{\"cursor\": {\"session_id\": \"" + sessionID + "\",\"offset\":\"" + (file.size - blob.size) + "\"},\"commit\": {\"path\":\"/render/" + filename + "\",\"mode\":{\".tag\":\"add\"}}, \"close\":true}"
},
"body": blob
})
.then((httpResponse) => {
if (httpResponse.ok){
console.log("HTTP RES : OK")
return httpResponse.ok
} else {
console.log("HTTP RES : NOT OK")
return !httpResponse.ok
}
})
.catch(err => console.log("[ERROR] UPLOAD_SESSION_FINISH : " + err));
})
}
}, Promise.resolve());
task.then(function(result) {
console.log('result:',result);
}).catch(function(error) {
console.error(error);
});
}
- Greg-DBDropbox Staff
Make sure you check the response body itself. It should contain a more specific error indicating what the issue is.
- varunvyas5678Explorer | Level 3
Response for the callout is:
Error in call to API function "files/upload_session/append:2": The given OAuth 2 access token is malformed.- Greg-DBDropbox Staff
That error message indicates that there's an issue with the access token value you're supplying with the API call. Check the access token you're sending and make sure you're using the exact value as it was provided to you by Dropbox. Don't add or remove any characters, make sure there's no stray whitespace, etc. (As a matter of security, do not share any access tokens or refresh tokens here.)
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,876 PostsLatest Activity: 3 hours agoIf 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 or Facebook.
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!