cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Corrupt saved file if I first don't save to disk (node)

Corrupt saved file if I first don't save to disk (node)

smr_software
New member | Level 2

Hi all, 

I'm using the api to save a file to Dropbox from node (meteor). My problem is, if I don't first save to disk (node) but directly to Dropbox, the result is a corrupted file.  Otherwise, If I first  save to node, read, and then save to DB, the file is saved perfect. 

In  the client (browser) I receive the file from the user and pass this: file.srcElement.result to server (node).  

In server, I write the file to disk: 

await writeFileAsync(fileName, blob, encoding) 
then read it from disk 
fileContent = await readFileAsync(fileName); 
get my Dropbox token ... 
 
write to Dropbox : 
 
await dbx.filesUpload({
                path: fileName, 
                contents: fileContent, 
                mode: { ".tag": "overwrite" }, 
                autorename: false 
            })
 
Everything works perfect and I can see the file is perfectly written to DB. Nevertheless,  I don't want to save the content first to disk, in order to save then to DB. 
 
Can somebody help me undertand what I'm missing here? 
 
Many thanks and bye ... 
1 Accepted Solution

Accepted Solutions

Re: Corrupt saved file if I first don't save to disk (node)

Здравко
Super Collaborator | Level 20

Hi @smr_software,

Did you take care for file decoding, not directly forward it?! Usually files get encoded somehow (base64, gzip,.. etc.) before transmitted from clients browser. :wink:

Hope this helps.

View solution in original post

3 Replies 3

Re: Corrupt saved file if I first don't save to disk (node)

Здравко
Super Collaborator | Level 20

Hi @smr_software,

Did you take care for file decoding, not directly forward it?! Usually files get encoded somehow (base64, gzip,.. etc.) before transmitted from clients browser. :wink:

Hope this helps.

View solution in original post

Re: Corrupt saved file if I first don't save to disk (node)

Greg-DB
Dropboxer

@smr_software The Dropbox filesUpload method will just upload the data supplied to it, so to follow on what Здравко said, it sounds like the issue is occurring before the Dropbox call. It may have to do with whatever format or encoding the data is in when you get it. 

Since this isn't exactly about the Dropbox API itself, I'm afraid I can't offer much help. You may be better suited asking about how to handle data like this in Node/Meteor in a more general forum, such as StackOverflow, or one specific to Node or Meteor. I also recommend adding some logging first to inspect the data through your code to see what is different and where.

Re: Corrupt saved file if I first don't save to disk (node)

smr_software
New member | Level 2

Well, yes, I suppose both answers are in a way ansewring the issue. It's not a DB issue but an encoding one. I'll research a little bit about this, or maybe try in another forum, a more general one, like Stackoverflow. 

Of course if I find the solutions I'll post it back here. 

Many thanks for your help and bye ... 

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    smr_software New member | Level 2
  • User avatar
    Greg-DB Dropboxer
  • User avatar
    Здравко Super Collaborator | Level 20
What do Dropbox user levels mean?
Need more support?