Using the dropbox javascript SDK, i'm attempting to upload some .wav audio files to a dropbox folder.
However, the files uploaded are unreadable and give a "audio error" when opened or previewed. The code I'm using is:
var Dropbox = require('dropbox').Dropbox;
var dbx = new Dropbox({ accessToken: 'accesstoken' });
dbx.filesUpload({path: filePath, contents: req.body.file, mode: 'overwrite'})
.then(function(response) {
console.log("audio saved!");
res.sendStatus(200);
})
.catch(function(error) {
console.error(error);
response.sendStatus(400);
});
filePath is the folder structure + name of the file, ex: /DropboxRoot/Audio/sounds.wav
For the contents, I have tried many things in the attempt that the data is being uploaded in the wrong format. So far I've tried:
- Blob - Blob(123456){size:123456, type:"audio/wav"}
- ArrayBuffer
Am I uploading the data incorrectly? The audio blob can be used successfully as audio before being sent to the server.
I record the audio using this free code and play it back by loading it to the source of an Audio element like so:
<audio controls>
<source src="" type="audio/wav" />
</audio>
The "source" is set to var url = (window.URL || window.webkitURL).createObjectURL(blob)
The audio blob can be used successfully as audio before being sent to the server.how are you both recording / generating this audio blob, then how are you playing it back? Maybe DropBox thinks it's a WAV, but its actually an MP3? Maybe it doesnt even have the proper file headers for a WAV, but is just the raw binary data?